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
- 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.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Scheduler API.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Scheduler API.
gcloud
- 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.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Scheduler API:
gcloud services enable scheduler.googleapis.com
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
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
Pada konsol Google Cloud, buka halaman App Engine.
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.
Pilih region untuk aplikasi Anda.
Perhatikan bahwa
europe-west
danus-central
masing-masing disebuteurope-west1
danus-central1
dalam perintah Cloud Scheduler.Setelah menetapkan region untuk aplikasi App Engine, Anda tidak dapat mengubahnya.
Jangan pilih akun layanan; akun layanan App Engine default akan digunakan.
Klik Berikutnya.
Aplikasi dikonfigurasi dan dibuat. Proses ini dapat memerlukan waktu beberapa menit.
Jangan download Cloud SDK; sebagai gantinya, klik Saya akan melakukannya nanti.
Anda akan melihat pesan Aplikasi App Engine Anda telah dibuat.
gcloud
Untuk membuat aplikasi App Engine, jalankan perintah
gcloud app create
:gcloud app create --region=REGION
Ganti
REGION
dengan lokasi tempat aplikasi berjalan. Perhatikan bahwaeurope-west
danus-central
masing-masing disebuteurope-west1
danus-central1
dalam perintah Cloud Scheduler.Setelah menetapkan region untuk aplikasi App Engine, Anda tidak dapat mengubahnya.
Anda dapat memeriksa region aplikasi yang ada dengan perintah berikut:
gcloud app describe
locationId
menunjukkan wilayah. Contoh:locationId: us-central
.