Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Cette page explique comment utiliser Cloud Scheduler pour exécuter un workflow selon une planification particulière, par exemple tous les lundis à 9 h ou toutes les 15 minutes. Vous pouvez configurer la planification dans la console Google Cloud ou à l'aide de Google Cloud CLI.
Remplacez SERVICE_ACCOUNT_NAME par un nom comportant entre 6 et 30 caractères. Il peut contenir des caractères alphanumériques minuscules et des tirets.
Une fois le compte de service créé, vous ne pouvez pas en modifier le nom.
SERVICE_ACCOUNT_NAME: nom du compte de service que vous avez créé précédemment.
Créez une tâche Cloud Scheduler qui déclenche votre workflow à l'aide du compte de service que vous avez créé précédemment pour l'authentification.
Notez que si vous appliquez la journalisation des appels, vous devez la configurer sur la page Workflows de la consoleGoogle Cloud . Pour en savoir plus, consultez les étapes suivantes.
Console
Pour planifier un workflow, accédez à la page Workflows de la console Google Cloud :
Sur la page "Workflows", sélectionnez un workflow pour accéder à sa page d'informations.
Sur la page Détails du workflow, cliquez sur editModifier.
Sur la page Modifier le workflow, sélectionnez Ajouter un déclencheur > Cloud Scheduler.
Le volet Créer une tâche Scheduler s'ouvre.
Définissez le planning :
Dans le champ Nom, saisissez un nom pour votre tâche Cloud Scheduler. Celui-ci doit être unique pour toutes les tâches de la même région.
Dans la liste Région, sélectionnez une région appropriée. Exemple : us-central1.
Dans le champ Fréquence, spécifiez un intervalle de temps que vous définissez au format unix-cron.
Par exemple, pour planifier l'exécution de votre workflow toutes les cinq minutes, saisissez */5 * * * *.
Dans la liste Fuseau horaire, sélectionnez le fuseau horaire que Cloud Scheduler doit utiliser pour interpréter la planification que vous fournissez. Vous pouvez effectuer une recherche par pays.
Cliquez sur Continuer.
Configurez l'exécution :
Dans le champ Argument du workflow, spécifiez les arguments d'exécution à transmettre à votre workflow avant l'exécution. Les arguments doivent être au format JSON. Par exemple : {"firstName":"Sherlock", "lastName":"Holmes"}.
Si votre workflow n'utilise pas d'arguments d'exécution, acceptez la valeur par défaut de {} ou laissez le champ vide.
Dans la liste Niveau de journalisation des appels du workflow, sélectionnez le niveau de journalisation des appels que vous souhaitez appliquer lors de l'exécution du workflow :
Non spécifié: aucun niveau de journalisation n'est spécifié. Il s'agit de l'option par défaut.
Un niveau de journalisation d'exécution est prioritaire sur tout niveau de journalisation de workflow, sauf si celui-ci n'est pas spécifié (valeur par défaut). Dans ce cas, le niveau de journalisation du workflow s'applique.
Erreurs uniquement: consigne toutes les exceptions interceptées, ou lorsqu'un appel est arrêté en raison d'une exception.
Tous les appels: consigne tous les appels aux sous-workflows ou aux fonctions de la bibliothèque, ainsi que leurs résultats.
Aucun journal: aucun journal d'appels.
Dans la liste Compte de service, sélectionnez le compte de service que vous avez créé précédemment.
Cliquez sur Créer.
Notez que si vous mettez à jour un workflow existant, vous n'avez pas besoin de le redéployer.
La tâche Cloud Scheduler est désormais répertoriée dans l'onglet Déclencheurs de la page Détails du workflow.
Si vous souhaitez mettre à jour ou supprimer la tâche, vous devez modifier le workflow :
Sur la page Détails du workflow, cliquez sur editModifier.
Dans la section Déclencheurs, recherchez le job que vous souhaitez modifier ou supprimer.
Cliquez sur editModifier la ressource ou sur deleteSupprimer la ressource.
gcloud
Ouvrez un terminal et saisissez la commande suivante :
FREQUENCY : intervalle de temps que vous définissez à l'aide d'un format unix-cron.
Par exemple, pour planifier l'exécution de votre workflow toutes les cinq minutes, saisissez */5 * * * *.
PROJECT_ID : ID de votre projet Google Cloud .
REGION_NAME: région dans laquelle se trouve le workflow, par exemple us-central1.
WORKFLOW_NAME: nom du workflow dont vous souhaitez planifier l'exécution.
DOUBLE_ESCAPED_JSON_STRING: encodage JSON des arguments que vous transmettez. Les guillemets doubles dans la chaîne entre guillemets sont échappés avec des barres obliques inverses (\). Par exemple : --message-body="{\"argument\": \"{\\\"foo\\\": \\\"bar\\\"}\"}"
TIME_ZONE: fuseau horaire que Cloud Scheduler doit utiliser pour interpréter la planification que vous fournissez. Par exemple : America/New_York.
SERVICE_ACCOUNT_NAME: nom du compte de service que vous avez créé précédemment.
Pour lister toutes les tâches d'un projet, procédez comme suit :
gcloudschedulerjobslist
Pour supprimer une tâche, procédez comme suit :
gcloudschedulerjobsdeleteJOB_NAME
Votre workflow s'exécute désormais selon la fréquence que vous avez définie.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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)"]]