Google Cloud Scheduler Create Job Quick Reference
06/15/2021
Google Cloud has a cloud based CRON job system which is highly scalable and resilient so you do not have to build it yourself. Here is a quick guide on how to use it.
First, let's start with the CRON scheduling. Even with https://cron.help it is hard to know how to set the time correctly, so here is a cheat sheet to get you started:
- Every Minute:
* * * * *
- Every 5 Minutes:
*/5 * * * *
- Every 15 Minutes:
*/15 * * * *
- Every 30 Minutes:
*/30 * * * *
- Every Hour:
*/60 * * * *
- Every Day at 6:30 AM:
30 6 * * * *
- Every Day at 5:30 PM:
30 17 * * * *
- Monthly on the 1st at 5:30PM:
30 17 1 * *
The first step is to go into the Google Cloud Console and enable the service. This is required before you do anything.
Then, you can set up a job via console or CLI.
Here is how you set it up via the console 👉 Creating and configuring cron jobs | Cloud Scheduler Documentation (google.com)
Using the gcloud CLI is here, but it is a bit complex: gcloud scheduler jobs create http | Cloud SDK Documentation (google.com)
To make this easy here is a simple command to use to get the majority of it working:
gcloud scheduler jobs create http {name_goes_here} --schedule="{cron_schedule}" --uri="{url_to_hit_when_ran}" --http-method="post" --headers="Content-Type=application/json,User-Agent=Google-Cloud-Scheduler" --time-zone="America/Los_Angeles"
- {name_goes_here} - any name you want to use
- {cron_schedule} - any of the examples above such as "* * * * *" for every minute
Easy to use and something you no longer have to manage. Here is a quick loom to help also 📺 here.