Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara menjalankan tugas Cloud Run sesuai jadwal menggunakan
Cloud Scheduler.
Jika Google Cloud project Anda berada di dalam perimeter Kontrol Layanan VPC dalam jaringan Virtual Private Cloud, lihat Menjalankan tugas sesuai jadwal dalam perimeter Kontrol Layanan VPC untuk mengetahui petunjuk cara menjadwalkan tugas untuk kasus penggunaan tersebut.
Peran yang diperlukan
Untuk mendapatkan izin yang Anda perlukan untuk operasi yang dijelaskan di halaman ini, minta administrator Anda untuk memberi Anda peran IAM pada tugas Cloud Run Anda:
Admin Cloud Scheduler
(roles/cloudscheduler.admin), atau peran khusus dengan izin
cloudscheduler.jobs.create
Cloud Run Invoker (roles/run.invoker)
untuk menjalankan tugas menggunakan Google Cloud CLI, atau Cloud Run Developer
(roles/run.developer) untuk menjalankan tugas menggunakan Google Cloud konsol
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-21 UTC."],[],[],null,["# Execute jobs on a schedule\n\nThis page describes how to execute Cloud Run jobs on a schedule using\nCloud Scheduler.\n\nIf your Google Cloud project is inside a VPC Service Controls perimeter in a\nVirtual Private Cloud network, see [Execute jobs on a schedule in a VPC Service Controls perimeter](/run/docs/execute/jobs-on-schedule-vpc-sc-perimeter) for instructions on how to schedule jobs for that use case.\n\nRequired roles\n--------------\n\nTo get the permissions that you need for the operations described on this page,\nask your administrator to grant you the IAM roles on your\nCloud Run job:\n\n- [Cloud Scheduler Admin](/iam/docs/understanding-roles#cloudscheduler.admin) (`roles/cloudscheduler.admin`), or a custom role with the `cloudscheduler.jobs.create` permission\n- [Cloud Run Invoker](/iam/docs/understanding-roles#run.invoker) (`roles/run.invoker`) to execute jobs using the Google Cloud CLI, or [Cloud Run Developer](/iam/docs/understanding-roles#run.developer) (`roles/run.developer`) to execute jobs using the Google Cloud console\n\nFor a list of IAM roles and permissions that are associated with\nCloud Run, see\n[Cloud Run IAM roles](/run/docs/reference/iam/roles)\nand [Cloud Run IAM permissions](/run/docs/reference/iam/permissions).\nIf your Cloud Run job interfaces with\nGoogle Cloud APIs, such as Cloud Client Libraries, see the\n[service identity configuration guide](/run/docs/configuring/jobs/service-identity).\nFor more information about granting roles, see\n[deployment permissions](/run/docs/reference/iam/roles#additional-configuration)\nand [manage access](/iam/docs/granting-changing-revoking-access).\n\nBefore you begin\n----------------\n\n[Create a Cloud Run job](/run/docs/create-jobs).\n\nConfigure a Cloud Run job to execute on a schedule\n--------------------------------------------------\n\nTo execute a Cloud Run job on a schedule: \n\n### Console\n\n1. [Go to Cloud Run jobs](https://console.cloud.google.com/run/jobs)\n\n2. Click the job you want to execute on a schedule.\n\n3. Click the **Triggers** tab.\n\n4. Click **Add Scheduler Trigger**.\n\n5. If you haven't yet enabled the Cloud Scheduler API for your project, you\n are prompted to do so in the far right panel: click **Enable API**.\n\n6. Fill out the Cloud Scheduler job form\n\n7. Under *Define a schedule*:\n\n 1. Give your Cloud Scheduler job a name.\n\n 2. Select a region for your Cloud Scheduler job. It does not need to\n match the region used for the Cloud Run job.\n\n 3. Specify the **frequency** for your job execution, using the [unix-cron](http://man7.org/linux/man-pages/man5/crontab.5.html) format, for example, `0 12 * * *`\n\n 4. Select your timezone.\n\n8. Click **Continue**.\n\n9. In the **Service Account** dropdown menu, select a service account\n that has the permission to invoke the current Cloud Run service.\n\n10. Click **Create** to create the Cloud Scheduler job that will execute\n the Cloud Run job at the specified frequency.\n\n### Command line\n\n1. Make sure you [create a Cloud Run job first](/run/docs/create-jobs).\n\n2. Run the command:\n\n ```bash\n gcloud scheduler jobs create http SCHEDULER_JOB_NAME \\\n --location SCHEDULER_REGION \\\n --schedule=\"\u003cvar translate=\"no\"\u003eSCHEDULE\u003c/var\u003e\" \\\n --uri=\"https://run.googleapis.com/v2/projects/\u003cvar translate=\"no\"\u003ePROJECT-ID\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eCLOUD_RUN_REGION\u003c/var\u003e/jobs/\u003cvar translate=\"no\"\u003eJOB-NAME\u003c/var\u003e:run\" \\\n --http-method POST \\\n --oauth-service-account-email PROJECT-NUMBER-compute@developer.gserviceaccount.com\n ```\n\n Replace\n - \u003cvar translate=\"no\"\u003eSCHEDULER_JOB_NAME\u003c/var\u003e with the name you want to give your scheduler job.\n - \u003cvar translate=\"no\"\u003eSCHEDULER_REGION\u003c/var\u003e with a region supported by Cloud Scheduler, for example, `europe-west2`.\n - \u003cvar translate=\"no\"\u003eCLOUD_RUN_REGION\u003c/var\u003e with the region for the your Cloud Run job. For preview, use `europe-west9`.\n - \u003cvar translate=\"no\"\u003eSCHEDULE\u003c/var\u003e with the desired frequency, for example `0 12 * * *`\n - \u003cvar translate=\"no\"\u003ePROJECT-ID\u003c/var\u003e with your project ID.\n - \u003cvar translate=\"no\"\u003ePROJECT-NUMBER\u003c/var\u003e with your project number.\n - \u003cvar translate=\"no\"\u003eJOB-NAME\u003c/var\u003e with your Cloud Run job.\n\n### Terraform\n\n\u003cbr /\u003e\n\nTo learn how to apply or remove a Terraform configuration, see\n[Basic Terraform commands](/docs/terraform/basic-commands).\nAdd the following to a [`google_cloud_run_v2_job`](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_v2_job) resource in your Terraform configuration: \n\n\u003cbr /\u003e\n\n resource \"google_cloud_scheduler_job\" \"job\" {\n provider = google-beta\n name = \"schedule-job\"\n description = \"test http job\"\n schedule = \"*/8 * * * *\"\n attempt_deadline = \"320s\"\n region = \"us-central1\"\n project = data.google_project.project.project_id\n\n retry_config {\n retry_count = 3\n }\n\n http_target {\n http_method = \"POST\"\n uri = \"https://${google_cloud_run_v2_job.default.location}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${data.google_project.project.number}/jobs/${google_cloud_run_v2_job.default.name}:run\"\n\n oauth_token {\n service_account_email = google_service_account.cloud_run_invoker_sa.email\n }\n }\n\n depends_on = [resource.google_project_service.cloudscheduler_api, resource.google_cloud_run_v2_job.default, resource.google_cloud_run_v2_job_iam_binding.binding]\n }\n\nCloud Scheduler will execute the Cloud Run job at the specified\nfrequency.\n\nWhat's next\n-----------\n\nAfter you use this feature, you can do the following:\n\n- [View job logs](/run/docs/logging)\n- [Monitor job performances](/run/docs/monitoring)\n- [Create a job](/run/docs/create-jobs)\n- [Execute a job](/run/docs/execute/jobs)\n- [Manage jobs](/run/docs/managing/jobs)\n- [Manage job executions](/run/docs/managing/job-executions)\n\n- [Set memory limits](/run/docs/configuring/jobs/memory-limits)\n\n- [Set environment variables](/run/docs/configuring/jobs/environment-variables)"]]