Pianificazione di un flusso di lavoro utilizzando Cloud Scheduler
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa pagina mostra come utilizzare Cloud Scheduler per
eseguire un flusso di lavoro in base a una pianificazione specifica, ad esempio ogni lunedì alle 9:00 o ogni
15 minuti. Puoi configurare la pianificazione nella console Google Cloud o utilizzando
Google Cloud CLI.
Sostituisci SERVICE_ACCOUNT_NAME con un nome compreso tra 6 e 30
caratteri. Può contenere caratteri alfanumerici minuscoli e trattini.
Una volta creato un account di servizio, non puoi modificarne il nome.
SERVICE_ACCOUNT_NAME: il nome del account di servizio che
hai creato in precedenza.
Crea un job Cloud Scheduler che attiva il flusso di lavoro utilizzando l'account di servizio che hai creato in precedenza per l'autenticazione.
Tieni presente che se stai applicando
il registro chiamate, devi configurarlo
tramite la pagina Workflows nella
consoleGoogle Cloud . Per maggiori dettagli, consulta i passaggi seguenti.
Console
Per pianificare un flusso di lavoro, vai alla pagina Workflows nella console Google Cloud :
Nella pagina Workflows, seleziona un workflow per accedere alla pagina dei dettagli.
Nella pagina Dettagli del flusso di lavoro, fai clic su
editModifica.
Nella pagina Modifica flusso di lavoro, seleziona Aggiungi nuovo trigger >
Cloud Scheduler.
Viene visualizzato il riquadro Crea un job Scheduler.
Definisci la pianificazione:
Nel campo Nome, inserisci un nome per il job Cloud Scheduler. Deve essere univoco per i job nella stessa regione.
Nell'elenco Regione, seleziona una
regione appropriata, ad esempio us-central1.
Nel campo Frequenza, specifica un intervallo di tempo definito
in un formato unix-cron.
Ad esempio, per programmare l'esecuzione del flusso di lavoro ogni 5 minuti, digita
*/5 * * * *.
Nell'elenco Fuso orario, seleziona il fuso orario
che Cloud Scheduler deve utilizzare per interpretare la pianificazione che
fornisci. Puoi cercare per paese.
Fai clic su Continua.
Configura l'esecuzione:
Nel campo Argomento del flusso di lavoro, specifica gli argomenti di runtime
da passare al flusso di lavoro prima dell'esecuzione. Gli argomenti devono essere in formato JSON. Ad esempio:
{"firstName":"Sherlock", "lastName":"Holmes"}.
Se il flusso di lavoro non utilizza argomenti runtime, accetta il valore predefinito di
{} o lascia il campo vuoto.
Nell'elenco Livello registro chiamate del flusso di lavoro, seleziona il livello di
registrazione delle chiamate
che vuoi applicare durante l'esecuzione del flusso di lavoro:
Non specificato: non è specificato alcun livello di logging. Questa è l'impostazione predefinita.
Un livello di log dell'esecuzione ha la precedenza su qualsiasi livello di log del workflow, a meno che
il livello di log dell'esecuzione non sia specificato (valore predefinito). In questo caso, viene applicato il
livello di log del workflow.
Solo errori: registra tutte le eccezioni rilevate o quando una chiamata viene interrotta
a causa di un'eccezione.
Tutte le chiamate: registra tutte le chiamate a flussi di lavoro secondari o funzioni di libreria e
i relativi risultati.
Nessun log: nessun registro chiamate.
Nell'elenco Service account, seleziona il account di servizio che hai creato in precedenza.
Fai clic su Crea.
Tieni presente che se stai aggiornando un flusso di lavoro esistente, non devi
ridistribuirlo.
Il job Cloud Scheduler è ora elencato nella scheda Trigger
della pagina Dettagli flusso di lavoro.
Se vuoi aggiornare o eliminare il job, devi modificare il workflow:
Nella pagina Dettagli del flusso di lavoro, fai clic su
editModifica.
Nella sezione Trigger, individua il job che vuoi aggiornare o
eliminare.
Fai clic su editModifica risorsa o
deleteElimina risorsa.
gcloud
Apri un terminale e inserisci il seguente comando:
JOB_NAME: il nome che stai assegnando al tuo
job Cloud Scheduler.
FREQUENCY: un intervallo di tempo definito utilizzando un formato unix-cron.
Ad esempio, per programmare l'esecuzione del flusso di lavoro ogni 5 minuti, digita
*/5 * * * *.
PROJECT_ID: l'ID del tuo Google Cloud progetto.
REGION_NAME: la regione in cui si trova il flusso di lavoro, ad esempio
us-central1.
WORKFLOW_NAME: il nome del flusso di lavoro di cui vuoi pianificare l'esecuzione.
DOUBLE_ESCAPED_JSON_STRING: una codifica JSON di tutti gli argomenti
che stai passando. Le virgolette doppie all'interno della stringa tra virgolette
vengono precedute da una barra rovesciata (\). Ad esempio:
--message-body="{\"argument\": \"{\\\"foo\\\": \\\"bar\\\"}\"}"
TIME_ZONE: il
fuso orario
che Cloud Scheduler deve utilizzare per interpretare la pianificazione che
fornisci. Ad esempio: America/New_York.
SERVICE_ACCOUNT_NAME: il nome del account di servizio che
hai creato in precedenza.
Per elencare tutti i job in un progetto:
gcloudschedulerjobslist
Per eliminare un job:
gcloudschedulerjobsdeleteJOB_NAME
Il flusso di lavoro viene ora eseguito in base alla frequenza che hai definito.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[],[],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)"]]