Set task timeout (jobs)

Raw Text

Home

Docs

Cloud Run

Documentation

Guides

Stay organized with collections

Save and categorize content based on your preferences.

By default, each task runs for a maximum of 10 minutes: you can change this to a shorter time or a longer time up to up to 24 hours. Note that times greater than 1 hour are a Preview feature.

You set task timeout as described in this page. There is no explicit timeout on a job execution: when all tasks are done, the job execution is done.

In the case of retries, the timeout setting applies to each attempt of a task. If the task attempt does not complete within this time, it will be stopped.

The units specify a duration; for example, 10m5s is ten minutes and five seconds. If you don't specify a unit, seconds are assumed as the unit. For example, the value 10 is 10 seconds.

Using task timeouts greater than one hour

Preview — Jobs with task timeouts greater than one hour in Cloud Run

This feature is covered by the Pre-GA Offerings Terms of the Google Cloud Terms of Service. Pre-GA features might have limited support, and changes to pre-GA features might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions .

Jobs with task timeouts greater than one hour periodically undergo maintenance events. During a maintenance event, any in-progress tasks are migrated from the current machine to a different machine. This migration process preserves the entire state of the task. However, there is a brief pause in processing while the task is migrated.

Observing and handling maintenance events

Maintenance events are transparent; you do not have to make any changes to your container to handle maintenance events. Note that every time a task starts and finishes migrating, Cloud Run prints out a log message.

However, if you want to monitor or handle maintenance events in a specific way, you can catch the SIGTSTP signal, which is sent 10 seconds before a task is migrated. After migration, the task receives a SIGCONT signal immediately after the task is restarted.

The following Go sample is a function that catches these signals and prints out a log entry:

Set task timeout

To specify task timeout for a Cloud Run job:

Console

Go to Cloud Run

If you are configuring a new job, click the Jobs tab and fill out the initial job settings page as desired. If you are configuring an existing job, click the job, then click Edit .

Click Container, variables and secrets, connections, security to expand the job properties page.

Click the General tab. Specify the maximum duration for the job tasks in the current job, specifying both the amount of time and the units: for example, 10m5s is ten minutes and five seconds.

Click Create or Update .

Command line

For a job you are creating: gcloud run jobs create JOB_NAME --image IMAGE_URL --task-timeout TIMEOUT Replace JOB_NAME with the name of your job. IMAGE_URL with a reference to the container image, for example, us-docker.pkg.dev/cloudrun/container/job:latest . TIMEOUT with the maximum duration for the job tasks, specifying the amount of time and the units: for example, 10m5s is ten minutes and five seconds.

For a job you are updating: gcloud run jobs update JOB_NAME --task-timeout TIMEOUT

YAML

Download and view existing job configuration using the gcloud run jobs describe --format export command, which yields cleaned results in YAML format. Then modify the fields described below and upload the modified YAML using the gcloud run jobs replace command. Make sure you only modify fields as documented.

To view and download the configuration: gcloud run jobs describe JOB_NAME --format export > job.yaml

Update the timeoutSeconds: attribute: apiVersion: run.googleapis.com/v1 kind: Job metadata: name: JOB spec: template: spec: template: spec: containers: - image: IMAGE timeoutSeconds: TIMEOUT Replace TIMEOUT with the maximum duration for the job tasks, specifying the amount of time and the units: for example, 10m5s is ten minutes and five seconds. You can also specify more configuration such as environment variables or memory limits.

Update the existing job configuration: gcloud run jobs replace job.yaml

Terraform

To learn how to apply or remove a Terraform configuration, see Basic Terraform commands .

To specify task timeout for a Cloud Run job, use google_cloud_run_v2_job resource and apply the following snippet to your main.tf file:

run/jobs_task_timeout_create/main.tf

View on GitHub

Feedback

View task timeout settings

To view the current task timeout settings for your Cloud Run job:

Console

Go to Cloud Run jobs

Click the job you are interested in to open the Job details page.

Click the Configuration tab.

Locate the task timeout setting in the configuration details.

Command line

Use the following command: gcloud run jobs describe JOB_NAME

Locate the task timeout setting in the returned configuration.

Single Line Text

Home. Docs. Cloud Run. Documentation. Guides. Stay organized with collections. Save and categorize content based on your preferences. By default, each task runs for a maximum of 10 minutes: you can change this to a shorter time or a longer time up to up to 24 hours. Note that times greater than 1 hour are a Preview feature. You set task timeout as described in this page. There is no explicit timeout on a job execution: when all tasks are done, the job execution is done. In the case of retries, the timeout setting applies to each attempt of a task. If the task attempt does not complete within this time, it will be stopped. The units specify a duration; for example, 10m5s is ten minutes and five seconds. If you don't specify a unit, seconds are assumed as the unit. For example, the value 10 is 10 seconds. Using task timeouts greater than one hour. Preview — Jobs with task timeouts greater than one hour in Cloud Run. This feature is covered by the Pre-GA Offerings Terms of the Google Cloud Terms of Service. Pre-GA features might have limited support, and changes to pre-GA features might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions . Jobs with task timeouts greater than one hour periodically undergo maintenance events. During a maintenance event, any in-progress tasks are migrated from the current machine to a different machine. This migration process preserves the entire state of the task. However, there is a brief pause in processing while the task is migrated. Observing and handling maintenance events. Maintenance events are transparent; you do not have to make any changes to your container to handle maintenance events. Note that every time a task starts and finishes migrating, Cloud Run prints out a log message. However, if you want to monitor or handle maintenance events in a specific way, you can catch the SIGTSTP signal, which is sent 10 seconds before a task is migrated. After migration, the task receives a SIGCONT signal immediately after the task is restarted. The following Go sample is a function that catches these signals and prints out a log entry: Set task timeout. To specify task timeout for a Cloud Run job: Console. Go to Cloud Run. If you are configuring a new job, click the Jobs tab and fill out the initial job settings page as desired. If you are configuring an existing job, click the job, then click Edit . Click Container, variables and secrets, connections, security to expand the job properties page. Click the General tab. Specify the maximum duration for the job tasks in the current job, specifying both the amount of time and the units: for example, 10m5s is ten minutes and five seconds. Click Create or Update . Command line. For a job you are creating: gcloud run jobs create JOB_NAME --image IMAGE_URL --task-timeout TIMEOUT Replace JOB_NAME with the name of your job. IMAGE_URL with a reference to the container image, for example, us-docker.pkg.dev/cloudrun/container/job:latest . TIMEOUT with the maximum duration for the job tasks, specifying the amount of time and the units: for example, 10m5s is ten minutes and five seconds. For a job you are updating: gcloud run jobs update JOB_NAME --task-timeout TIMEOUT. YAML. Download and view existing job configuration using the gcloud run jobs describe --format export command, which yields cleaned results in YAML format. Then modify the fields described below and upload the modified YAML using the gcloud run jobs replace command. Make sure you only modify fields as documented. To view and download the configuration: gcloud run jobs describe JOB_NAME --format export > job.yaml. Update the timeoutSeconds: attribute: apiVersion: run.googleapis.com/v1 kind: Job metadata: name: JOB spec: template: spec: template: spec: containers: - image: IMAGE timeoutSeconds: TIMEOUT Replace TIMEOUT with the maximum duration for the job tasks, specifying the amount of time and the units: for example, 10m5s is ten minutes and five seconds. You can also specify more configuration such as environment variables or memory limits. Update the existing job configuration: gcloud run jobs replace job.yaml. Terraform. To learn how to apply or remove a Terraform configuration, see Basic Terraform commands . To specify task timeout for a Cloud Run job, use google_cloud_run_v2_job resource and apply the following snippet to your main.tf file: run/jobs_task_timeout_create/main.tf. View on GitHub. Feedback. View task timeout settings. To view the current task timeout settings for your Cloud Run job: Console. Go to Cloud Run jobs. Click the job you are interested in to open the Job details page. Click the Configuration tab. Locate the task timeout setting in the configuration details. Command line. Use the following command: gcloud run jobs describe JOB_NAME. Locate the task timeout setting in the returned configuration.