Search code examples
gogoogle-cloud-platformsleepserverlessserverless-architecture

how to schedule something from cloud function


I have a serverless app running as google cloud function triggered by bucket object finalize. at the end of the function logic I want to call another action (also function) after exactly one minute (or T time). currently couldn't come up with any way to call another action in one minute and had to use sleep in my app.

the problem with sleep is that I have 60 seconds that the cloud function cost money while no real work is being done.

any suggestion on how to execute something from cloud function in T time so I can just exit from function and save money?

keeping in mind I would like to keep it serverless and using GCP.


Solution

  • Use Cloud Tasks with a HTTP target task and schedule_time:

    1. GCS finalize event triggers Cloud Function A
    2. In Cloud Function A, create a HTTP target task with schedule_time = now + 60s and url = URL of Cloud Function B
    3. After a minute has passed, the Cloud Task is scheduled and Cloud Function B will is invoked