4

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.

Itamar Lavender
  • 959
  • 7
  • 20
  • 2
    This means using another service and that usually also costs money. You can use either a state based design or a time scheduled design: Cloud Tasks / Cloud Scheduler. – John Hanley Jul 26 '19 at 17:19
  • Thank you John, however this is what this question is about. my app already uses "cloud.google.com/go/scheduler/apiv1" but this is crontab style scheduler for recurring executions. other services I know of such pubsub do not offer any mechanism I could use just for that. I understand each solution will have it's cost but I think it should be lower than sleep for 60 seconds inside cloud function – Itamar Lavender Jul 26 '19 at 19:19
  • Did you calculate the cost for sleeping for 60 seconds? You receive up to 1 million seconds of compute per month free. https://cloud.google.com/functions/pricing-summary/ The actual cost is not that simple, but the required details are present in your question. – John Hanley Jul 26 '19 at 22:49
  • We're already beyond free tier. I'm looking for an engineering solution/idea not an accountant one. – Itamar Lavender Jul 27 '19 at 06:27
  • 1
    Edit your question where you state "and save money?" I have not provided a solution, just comments to help formulate the best question. – John Hanley Jul 27 '19 at 07:07

1 Answers1

0

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
Aleksi
  • 4,483
  • 33
  • 45
  • Thank you @Aleksi this was definitely thought of but the authentication mechanism is unsuitable for us as HTTP has to be some pre-shared secret/key. Having that said, this is totally applicable solution. – Itamar Lavender Aug 21 '19 at 14:13