Menyiapkan lingkungan Anda

Sebelum menjadwalkan dan menjalankan tugas cron, Anda harus menyiapkan project dan lingkungan Google Clouduntuk Cloud Scheduler.

Mengaktifkan Cloud Scheduler API

Gunakan petunjuk berikut untuk membuat atau memilih project Google Cloud dan mengaktifkan Cloud Scheduler API.

Konsol

  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

Menyiapkan autentikasi

Cara Anda melakukan autentikasi ke Cloud Scheduler bergantung pada antarmuka yang Anda gunakan untuk mengakses API dan lingkungan tempat kode Anda berjalan.

Untuk mengetahui informasi selengkapnya, lihat Mengautentikasi ke Cloud Scheduler dan Menggunakan autentikasi dengan target HTTP.

Menambahkan aplikasi App Engine

Jika akan menggunakan target HTTP App Engine, Anda harus menambahkan aplikasi App Engine ke project. Aplikasi ini berfungsi sebagai lokasi layanan Cloud Scheduler dan pengendali tugas itu sendiri, yang melakukan pekerjaan yang terkait dengan tugas Cloud Scheduler, dan menampilkan konfirmasi sebagai respons.

Jika ingin memiliki pengendali tugas App Engine yang tidak ada dalam project, Anda harus memilih target HTTP. Dalam hal ini, Anda tidak memerlukan aplikasi App Engine dalam project.

Konsol

  1. Pada konsol Google Cloud, buka halaman App Engine.

    Buka App Engine

  2. Pada dialog Welcome to App Engine, lakukan salah satu hal berikut:

    • Jika sudah membuat aplikasi App Engine dan ada pesan Aplikasi App Engine Anda telah dibuat yang ditampilkan, Anda dapat melewati langkah-langkah yang tersisa di bagian ini.

      atau

    • Jika Anda belum membuat aplikasi App Engine, klik Create application, lalu lanjutkan dengan langkah-langkah lainnya di bagian ini.

  3. Pilih region untuk aplikasi Anda.

    Perhatikan bahwa europe-west dan us-central masing-masing disebut europe-west1 dan us-central1 dalam perintah Cloud Scheduler.

    Setelah menetapkan region untuk aplikasi App Engine, Anda tidak dapat mengubahnya.

  4. Jangan pilih akun layanan; akun layanan App Engine default akan digunakan.

  5. Klik Berikutnya.

    Aplikasi dikonfigurasi dan dibuat. Proses ini dapat memerlukan waktu beberapa menit.

  6. Jangan download Cloud SDK; sebagai gantinya, klik Saya akan melakukannya nanti.

    Anda akan melihat pesan Aplikasi App Engine Anda telah dibuat.

gcloud

  1. Untuk membuat aplikasi App Engine, jalankan perintah gcloud app create:

    gcloud app create --region=REGION
    

    Ganti REGION dengan lokasi tempat aplikasi berjalan. Perhatikan bahwa europe-west dan us-central masing-masing disebut europe-west1 dan us-central1 dalam perintah Cloud Scheduler.

    Setelah menetapkan region untuk aplikasi App Engine, Anda tidak dapat mengubahnya.

  2. Anda dapat memeriksa region aplikasi yang ada dengan perintah berikut:

    gcloud app describe
    

    locationId menunjukkan wilayah. Contoh: locationId: us-central.