[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Schedule a workflow using Cloud Scheduler\n\nThis page shows you how to use [Cloud Scheduler](/scheduler/docs) to\nrun a workflow on a particular schedule, such as every Monday at 9 AM or every\n15 minutes. You can configure the schedule either in the Google Cloud console or by\nusing the Google Cloud CLI.\n\nBefore you begin\n----------------\n\n1. If you do not already have a workflow that you want to schedule, [create and deploy one](/workflows/docs/creating-updating-workflow#creating_a_workflow).\n2.\n\n\n Enable the Cloud Scheduler API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudscheduler.googleapis.com)\nOr, in a terminal, enter the following command: \n\n```bash\ngcloud services enable cloudscheduler.googleapis.com\n```\n\nSchedule a workflow\n-------------------\n\n1. Create a [service account](/workflows/docs/authentication)\n so that Cloud Scheduler can make requests to the Workflows API:\n\n ```bash\n gcloud iam service-accounts create SERVICE_ACCOUNT_NAME\n ```\n\n Replace \u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT_NAME\u003c/var\u003e with a name that is between 6 and 30\n characters. It can contain lowercase alphanumeric characters and dashes.\n After you create a service account, you cannot change its name.\n2. To allow the principal that will run your Cloud Scheduler\n commands the ability to act as an Identity and Access Management (IAM) service\n account,\n [grant a role that allows the principal to impersonate the service account](/iam/docs/service-account-permissions#roles).\n\n3. Grant your new service account the\n [workflows.invoker](/workflows/docs/access-control#roles) role so that the\n account has permission to trigger your workflow:\n\n \u003cbr /\u003e\n\n ```bash\n gcloud projects add-iam-policy-binding PROJECT_ID \\\n --member serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com \\\n --role roles/workflows.invoker\n ```\n\n \u003cbr /\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of your Google Cloud project.\n - \u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT_NAME\u003c/var\u003e: the name of the service account that you previously created.\n4. Create a Cloud Scheduler job that triggers your workflow, using the\n service account you previously created to authenticate.\n\n Note that if you are applying\n [call logging](/workflows/docs/log-workflow#call_logging), you must configure\n call logging through the **Workflows** page in the\n Google Cloud console. For details, refer to the following steps. \n\n ### Console\n\n 1. To schedule a workflow, go to the **Workflows** page in the Google Cloud console:\n\n\n [Go to Workflows](https://console.cloud.google.com/workflows)\n\n \u003cbr /\u003e\n\n 2. On the Workflows page, select a workflow to go to its\n details page.\n\n 3. On the **Workflow details** page, click\n *edit* **Edit**.\n\n 4. On the **Edit workflow** page, select **Add new trigger \\\u003e\n Cloud Scheduler**.\n\n The **Create a Scheduler job** pane opens.\n 5. Define the schedule:\n\n 1. In the **Name** field, enter a name for your Cloud Scheduler\n job. It must be unique across the jobs in the same region.\n\n 2. In the **Region** list, select an appropriate\n [region](/workflows/docs/locations); for example, **us-central1**.\n\n 3. In the **Frequency** field, specify a time interval that you define\n in a [unix-cron](/scheduler/docs/configuring/cron-job-schedules) format.\n For example, to schedule your workflow to execute every 5 minutes, type\n `*/5 * * * *`.\n\n 4. In the **Timezone** list, select the [time zone](/sdk/gcloud/reference/scheduler/jobs/create/http#--time-zone)\n that Cloud Scheduler should use to interpret the schedule you\n provide. You can search by country.\n\n 6. Click **Continue**.\n\n 7. Configure the execution:\n\n 1. In the **Workflow's argument** field, specify any [runtime arguments](/workflows/docs/passing-runtime-arguments)\n to pass to your workflow before execution. Arguments must be in JSON\n format. For example:\n `{\"firstName\":\"Sherlock\", \"lastName\":\"Holmes\"}`.\n If your workflow doesn't use runtime arguments, accept the default of\n `{}`, or leave the field blank.\n\n 2. In the **Workflow's call log level** list, select the level of\n [call logging](/workflows/docs/log-workflow#call_logging)\n that you want to apply during the execution of the workflow:\n\n - **Not specified**: no logging level is specified. This is the default. An execution log level takes precedence over any workflow log level, unless the execution log level is not specified (the default); in that case, the workflow log level applies.\n - **Errors only**: log all caught exceptions; or when a call is stopped due to an exception.\n - **All calls**: log all calls to subworkflows or library functions and their results.\n - **No logs**: no call logging.\n 3. In the **Service account** list, select the service account that\n you previously created.\n\n 8. Click **Create**.\n\n Note that if you are updating an existing workflow, you do *not* need\n to redeploy the workflow.\n\n The Cloud Scheduler job is now listed on the **Triggers**\n tab of the **Workflow details** page.\n 9. If you want to update or delete the job, you must edit the workflow:\n\n 1. On the **Workflow details** page, click *edit* **Edit**.\n 2. In the **Triggers** section, find the job you want to update or delete.\n 3. Click *edit* **Edit resource** or *delete* **Delete resource**.\n\n ### gcloud\n\n 1. Open a terminal and enter the following command:\n\n ```bash\n gcloud scheduler jobs create http JOB_NAME \\\n --schedule=\"\u003cvar translate=\"no\"\u003eFREQUENCY\u003c/var\u003e\" \\\n --uri=\"https://workflowexecutions.googleapis.com/v1/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eREGION_NAME\u003c/var\u003e/workflows/\u003cvar translate=\"no\"\u003eWORKFLOW_NAME\u003c/var\u003e/executions\" \\\n --message-body=\"{\\\"argument\\\": \\\"\u003cvar translate=\"no\"\u003eDOUBLE_ESCAPED_JSON_STRING\u003c/var\u003e\\\"}\" \\\n --time-zone=\"\u003cvar translate=\"no\"\u003eTIME_ZONE\u003c/var\u003e\" \\\n --oauth-service-account-email=\"\u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT_NAME\u003c/var\u003e@\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e.iam.gserviceaccount.com\"\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eJOB_NAME\u003c/var\u003e: the name you are giving to your Cloud Scheduler job.\n - \u003cvar translate=\"no\"\u003eFREQUENCY\u003c/var\u003e: a time interval you define using a [unix-cron](/scheduler/docs/configuring/cron-job-schedules) format. For example, to schedule your workflow to execute every 5 minutes, type `*/5 * * * *`.\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of your Google Cloud project.\n - \u003cvar translate=\"no\"\u003eREGION_NAME\u003c/var\u003e: the region your Workflow is in, such as `us-central1`.\n - \u003cvar translate=\"no\"\u003eWORKFLOW_NAME\u003c/var\u003e: the name of the workflow you want to schedule execution of.\n - \u003cvar translate=\"no\"\u003eDOUBLE_ESCAPED_JSON_STRING\u003c/var\u003e: a JSON encoding of any arguments you are passing. The double quotation marks inside the quoted string are escaped using backslashes (\\\\). For example: `--message-body=\"{\\\"argument\\\": \\\"{\\\\\\\"foo\\\\\\\": \\\\\\\"bar\\\\\\\"}\\\"}\"`\n - \u003cvar translate=\"no\"\u003eTIME_ZONE\u003c/var\u003e: the [time zone](/sdk/gcloud/reference/scheduler/jobs/create/http#--time-zone) that Cloud Scheduler should use to interpret the schedule you provide. For example: `America/New_York`.\n - \u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT_NAME\u003c/var\u003e: the name of the service account that you previously created.\n 2. To list all jobs in a project:\n\n ```bash\n gcloud scheduler jobs list\n ```\n\n \u003cbr /\u003e\n\n 3. To delete a job:\n\n ```bash\n gcloud scheduler jobs delete JOB_NAME\n ```\n\n \u003cbr /\u003e\n\nYour workflow now executes according to the frequency you have defined.\n| **Note:** Each execution of a workflow incurs costs, as detailed in [Workflows pricing](/workflows/pricing). To stop incurring costs from a scheduled workflow, [delete the Cloud Scheduler job](/sdk/gcloud/reference/scheduler/jobs/delete).\n\nWhat's next\n-----------\n\n- [Use IAM to control access](/workflows/docs/use-iam-for-access)\n- [Pass runtime arguments in an execution request](/workflows/docs/passing-runtime-arguments)\n- [Tutorial: Schedule Workflows with Cloud Scheduler](/scheduler/docs/tut-workflows)"]]