Configura l'ambiente

Prima di pianificare ed eseguire un cron job, devi configurare il Google Cloud progetto e l'ambiente per Cloud Scheduler.

Abilita l'API Cloud Scheduler

Segui le istruzioni riportate di seguito per creare o selezionare un Google Cloud progetto e per abilitare l'API Cloud Scheduler.

Console

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Cloud Scheduler API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Cloud Scheduler API.

    Enable the API

gcloud

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. Install the Google Cloud CLI.
  3. To initialize the gcloud CLI, run the following command:

    gcloud init
  4. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  5. Make sure that billing is enabled for your Google Cloud project.

  6. Enable the Cloud Scheduler API:

    gcloud services enable scheduler.googleapis.com
  7. Install the Google Cloud CLI.
  8. To initialize the gcloud CLI, run the following command:

    gcloud init
  9. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  10. Make sure that billing is enabled for your Google Cloud project.

  11. Enable the Cloud Scheduler API:

    gcloud services enable scheduler.googleapis.com

Configura l'autenticazione

Il modo in cui esegui l'autenticazione in Cloud Scheduler dipende dall'interfaccia che utilizzi per accedere all'API e dall'ambiente in cui viene eseguito il codice.

Per ulteriori informazioni, consulta Eseguire l'autenticazione in Cloud Scheduler e Utilizzare l'autenticazione con i target HTTP.

Aggiungere un'applicazione App Engine

Se intendi utilizzare un target HTTP App Engine, devi aggiungere un'applicazione App Engine al tuo progetto. Questa app funge da posizione del servizio Cloud Scheduler e dall'handler del job stesso, che esegue il lavoro associato a un job Cloud Scheduler e restituisce un messaggio di conferma in risposta.

Se vuoi avere un gestore dei job di App Engine non nel tuo progetto, devi selezionare un target HTTP. In questo caso, non è necessaria un'app App Engine nel progetto.

Console

  1. Nella console Google Cloud, vai alla pagina App Engine.

    Vai ad App Engine

  2. Nella finestra di dialogo Ti diamo il benvenuto in App Engine, esegui una delle seguenti operazioni:

    • Se hai già creato un'applicazione App Engine e viene visualizzato il messaggio L'applicazione App Engine è stata creata, puoi saltare i passaggi rimanenti di questa sezione.

      o

    • Se non hai ancora creato un'applicazione App Engine, fai clic su Crea applicazione e continua con i passaggi rimanenti di questa sezione.

  3. Seleziona una regione per la tua applicazione.

    Tieni presente che europe-west e us-central sono chiamati, rispettivamente, europe-west1 e us-central1 nei comandi di Cloud Scheduler.

    Una volta impostata una regione per l'app App Engine, non puoi modificarla.

  4. Non selezionare un account di servizio. Verrà utilizzato il service account predefinito di App Engine.

  5. Fai clic su Avanti.

    L'applicazione è configurata e creata. L'operazione potrebbe richiedere alcuni minuti.

  6. Non scaricare Cloud SDK, ma fai clic su Lo farò più tardi.

    Dovresti visualizzare il messaggio L'applicazione App Engine è stata creata.

gcloud

  1. Per creare un'app App Engine, esegui il comando gcloud app create:

    gcloud app create --region=REGION
    

    Sostituisci REGION con la località in cui viene eseguita l'app. Tieni presente cheeurope-west e us-central si chiamano rispettivamente europe-west1 e us-central1 nei comandi di Cloud Scheduler.

    Dopo aver impostato una regione per l'app App Engine, non puoi modificarla.

  2. Puoi controllare la regione di un'app esistente con il seguente comando:

    gcloud app describe
    

    locationId indica la regione. Ad esempio: locationId: us-central.