1

I'm currently running 2 scripts on a weekly schedule on a raspberry pi with the following configuration:

Cron executes a python script at a fixed time weekly. This python script waits between 0 and 50 hours then runs python script A. It waits about 16 hours and runs script A again 3 more times every 8 hours (The script takes about 4x longer to run the first time). 8 hours after the 4th run it runs script B.

I would like to move my scripts to Google Cloud VM for improved reliability but running the VM 24/7 just to run 30 hours worth of computations over a 100 hour period is inefficient and expensive.

I know I can use Google Scheduler as my cron to initiate the VM weekly but I still risk letting it run up to 50 hours waiting for script A to run. I understand cron supports adding a random sleep interval as listed in the example here:

30 8-21/* * * * sleep ${RANDOM:0:2}m ; /path/to/script.php

However, from what I've discovered, Google Cloud Scheduler is limited to 60 minutes and rightfully so. In this case what are my options? Does Google Cloud Task support delayed triggering of VM (up to 50 hours)? Is this something Pub Sub would support instead?

My scripts use a python library that I don't think is compatible with Google App Engine so I would further need to figure how to trigger a specific script in the VM on trigger.

  • Just ran the pricing calculator for VM costs only: Running 24/7 as is on my pi on Google VM f1-micro and public ip would cost $12.85/month. Using Google Scheduler to run the 100 hour period at a fixed weekly time is $4.55/month. Randomizing the 50 hour delay to run my custom scheduler the remaining 50 hour period is 2.45/month. Running the processes for only the 30 processing hours needed is $1.50/month. – Alex Cooper May 04 '20 at 06:54
  • Please upvote this feature request: https://issuetracker.google.com/issues/142630271 – Joe Jul 05 '22 at 19:29

1 Answers1

0

You can use Cloud Scheduler and Pub/Sub to trigger a Cloud Function that will start your VM and execute your script. If you do not want your Compute Engine instances to be running 24/7, at the end of your script you can have your Cloud Function stop your VM.

You can find how to schedule compute instances with Cloud Scheduler here and how to use HTTP functions in Cloud Functions to start and stop your Compute Engine instance [1].

Most importantly, here is the documentation on how to use Cloud Scheduler and Pub/Sub to trigger a Cloud Function [2].

[1] https://cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule

[2] https://cloud.google.com/scheduler/docs/tut-pub-sub

[3] Cloud Functions: https://cloud.google.com/functions/docs/concepts/overview

Rajeevan
  • 150
  • 6