> [!WARNING]
>
> **Preview
> --- Cloud Run delayed jobs**
>
>
> This feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
> [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> Pre-GA features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

This page describes how to delay execution of a job. Delayed execution lets you
defer non-urgent tasks by up to a maximum duration of 12 hours. When you use
this feature your job is provisioned during a low utilization window, in
exchange for a lower price. See the
[pricing page](https://cloud.google.com/run/pricing) for details.

Specifically:

- The provisioning of a delayed job execution is potentially up to 12 hours, and the total runtime duration of all tasks in a delayed job execution is 12 hours. In combination, these requirements ensure that a delayed execution will complete within 24 hours.
- Given the above, the task timeout limit for a delayed job is 12 hours.
- When a delayed job's execution has reached the maximum duration limit, the execution is cancelled by the system.

### Regular jobs versus delayed jobs

Every Cloud Run job is created as either a regular job or a delayed
job.

Regardless of how the job was created, you can execute it as the other type.
For details see:

- [Execute a regular job as a delayed job](https://docs.cloud.google.com/run/docs/delayed-jobs.md.txt#execute_a_regular_job_as_a_delayed_job)
- [Execute a delayed job as a regular job](https://docs.cloud.google.com/run/docs/delayed-jobs.md.txt#execute_a_delayed_job_as_a_regular_job)

## Pricing

To learn more about the pricing for Cloud Run delayed jobs, see
[Cloud Run Pricing](https://cloud.google.com/run/pricing#delayed-jobs).

## Required roles


To get the permissions that
you need to create Cloud Run jobs,

ask your administrator to grant you the
following IAM roles:

- [Cloud Run Developer](https://docs.cloud.google.com/iam/docs/roles-permissions/run.md.txt#run.developer) (`roles/run.developer`) on the Cloud Run job
- [Service Account User](https://docs.cloud.google.com/iam/docs/roles-permissions/iam.md.txt#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the service identity
- [Artifact Registry Reader](https://docs.cloud.google.com/iam/docs/roles-permissions/artifactregistry.md.txt#artifactregistry.reader) (`roles/artifactregistry.reader`) on the Artifact Registry repository of the container images of the job


For a list of IAM roles and permissions that are associated with
Cloud Run, see
[Cloud Run IAM roles](https://docs.cloud.google.com/run/docs/reference/iam/roles.md.txt)
and [Cloud Run IAM permissions](https://docs.cloud.google.com/run/docs/reference/iam/permissions.md.txt).
If your Cloud Run job interfaces with
Google Cloud APIs, such as Cloud Client Libraries, see the
[service identity configuration guide](https://docs.cloud.google.com/run/docs/configuring/jobs/service-identity.md.txt).
For more information about granting roles, see
[deployment permissions](https://docs.cloud.google.com/run/docs/reference/iam/roles.md.txt#additional-configuration)
and [manage access](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).

## Create a delayed job

By default, when you create and execute a new job, execution starts as soon as
possible.

With the delayed jobs feature, you can create a job that has delayed execution
built in from the point of creation:

### Console

1. In the Google Cloud console, go to the Cloud Run page:

   [Go to Cloud Run](https://console.cloud.google.com/run)
2. Select **Jobs** from the Cloud Run navigation menu, and click
   **Deploy container** to display the **Create job** form.

   1. Fill out the fields in the **Create job** form, as described in
      [Create jobs](https://docs.cloud.google.com/run/docs/create-jobs.md.txt#job).

   2. Select **Delay execution** to defer execution up to 12 hours.

### gcloud

Create the job using the `--delay-execution` flag:

```bash
gcloud beta run jobs create JOB_NAME \
  --image IMAGE_URL \
  --delay-execution \
  --region=REGION
```

If you created your job as a delayed job, you don't need to include the
`--delay-execution` flag to execute it:

```bash
gcloud beta run jobs execute JOB_NAME \
  --region=REGION
```

### YAML

Update your `job.yaml` with the `delayExecution` attribute se to `true`:

```yaml
apiVersion: run.googleapis.com/v1
kind: Job
metadata:
  name: JOB_NAME
spec:
  delayExecution: "true"
```

## Execute a regular job as a delayed job

To execute a regular job as a delayed job:

### Console

1. In the Google Cloud console, go to the Cloud Run page:

   [Go to Cloud Run](https://console.cloud.google.com/run)
2. Click the name of the job you want to edit.

3. Click **View \& edit job configuration**.

4. Select **Delayed execution**.

5. Click **Update**.

### gcloud

Run the following command:

```bash
gcloud beta run jobs execute JOB_NAME \
  --async \
  --delay-execution \
  --region=REGION
```

### YAML

Update your `job.yaml` with the `delayExecution` attribute set to `true`:

```yaml
apiVersion: run.googleapis.com/v1
kind: Job
metadata:
  name: JOB_NAME
spec:
  delayExecution: "true"
```

## Execute a delayed job as a regular job

When you disable delayed execution, the job is updated to be a regular job. This
means that the next time you execute this job, it executes as soon as possible.

To disable delayed execution:

### Console

1. In the Google Cloud console, go to the Cloud Run page:

   [Go to Cloud Run](https://console.cloud.google.com/run)
2. Click the name of the job you want to edit.

3. Click **View \& edit job configuration**.

4. Unselect **Delayed execution**.

5. Click **Update**.

### gcloud


Use the `--no-delay-execution` flag. You can also use this flag with the
`update` commands. If you use this flag for a regular job, it updates the job
to disable delayed execution.

```bash
gcloud beta run jobs update JOB_NAME \
  --image IMAGE_URL \
  --no-delay-execution \
  --region=REGION
```

### YAML

Update your `job.yaml` with the `delayExecution` attribute set to `false`:

```yaml
apiVersion: run.googleapis.com/v1
kind: Job
metadata:
  name: JOB_NAME
spec:
  delayExecution: "false"
```

## Execute a delayed job on creation or update

When you create a delayed job with the `--execute-now` flag, it will trigger
the execution on creation and the job will run at some point in next 12 hours.

To execute a delayed job upon creation or update:

### Console

1. In the Google Cloud console, go to the Cloud Run **Jobs** page:

   [Go to Cloud Run jobs](https://console.cloud.google.com/run/jobs)
2. If you have an existing delayed job, click the job to display the job details
   page, then select **View \& edit job configuration** . If you are creating a
   new delayed job, select **Deploy container**.

3. Go to the bottom of the page and check the
   **Execute job immediately** box before creating or updating the job.

### gcloud

Specify the [`--execute-now`](https://docs.cloud.google.com/sdk/gcloud/reference/run/jobs/create.md.txt#--execute-now)
flag when creating or updating a delayed job:

- Creating a job:

  ```bash
  gcloud run jobs create JOB_NAME \
    --image IMAGE_URL \
    --delay-execution \
    --execute-now \
    --region=REGION
  ```
- Updating a job:

  ```bash
  gcloud run jobs update JOB_NAME \
    --execute-now \
    --region=REGION
  ```