Search code examples
google-cloud-platformschedulergoogle-cloud-pubsubgoogle-cloud-scheduler

Google Cloud Scheduler to start a task after a specific time every day, but only if a Pub/Sub message arrives


Is it possible to achieve interoperability between a scheduler and a pub/sub in the Google Cloud, so that a task is triggered after a specific time every day, but only if a message arrives?

UPDATED:

Example would be a task scheduled for 10:00 am waits for a msg (a pre-requisite).

  1. At 10:00 the msg has not arrived. The job is not triggered. The msg arrives at 11:00. The job is triggered. (It can then send a msg to start the task to be executed)
  2. At 09:00 the msg arrives. The job is not executed. At 10:00 the job is triggered.
  3. The msg never arrives. The job is never executed.

Solution

  • Your puzzle seems to be an excellent match for using Cloud Tasks. At a high level, I would imagine you writing a Cloud Function that subscribes to the topic that is being published upon. The Cloud Function would contain your processing logic:

    1. Received after 10:00am, run your job immediately.
    2. Received before 10:00am, use Cloud Tasks to post a a task to run your job at 10:00am.

    ... and that's it.