0

I am working on an application where I have to send notification to the users regarding some job, and user has to accept the job within 1 minute, if he doesn't, the job's request should be sent to the next user.

I am using firestore as a database. When I create a job, trigger will send notification to the assigned user. Now I have to wait for 60 seconds to confirm if user has accepted the job and started the procedure, if not I have to assign that job to the new user.

I am not sure how I can create such procedure where cloud functions are executed post delayed.

Example: First execution will be done by trigger, and it will order for second execution after 60 seconds. Second execution checks if job is accepted, if so it will terminate and demands no post delayed execution, if job is not accepted, it will repeat the procedure of first execution and request for third execution after 60 seconds.

What are the available resources in google cloud to achieve this?

Thanks

Ankit Pise
  • 1,243
  • 11
  • 30
  • There is no built-in provider/support for delayed execution of a Cloud Function call. You can accomplish something like it by: 1) storing the tasks and their time-outs in the database, 2) [using a scheduled trigger](https://firebase.googleblog.com/2019/04/schedule-cloud-functions-firebase-cron.html) to run code every minute or so, 3) checking what tasks have expired since last time. – Frank van Puffelen May 13 '19 at 14:57
  • That's what I am doing for now, but I think it is not very scalable since job list will in expanding so will be the users list. Single job handling all these tasks every minute could cause delay. The last job executed will be left with less time to accept before next execution starts, or worst case, it might not finish execution within 60 seconds and cyclers might overlap. – Ankit Pise May 13 '19 at 15:29

1 Answers1

4

You can use Cloud Tasks to schedule a delayed call back to a Cloud Function.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441