2
votes

I have job(script) which is written in nodejs.

I have another API which writes data (Id and time-t1) to the Cloud Spanner. As soon as the API is a hit I want to run the same job at given time-t1 and pass id as parameter

Can I write some code in my API which will trigger the job at a given time (Note - for a single hit on API job should run job only once). I tried searching on the net but could only find periodic scheduler.

1
Have you considered leveraging Cloud Tasks ... see ... cloud.google.com/tasks/docs ... this capability offers one the ability to forward schedule work to be performed at a subequent date/time. - Kolban
@Kolban I want to run the cloud task at specific time T1. Then I would like to run the same task again at specific time T2. Time T1 and T2 are not known beforehand. They are user-configurable. I don't think cloud task provides this functionality. - Ankur Verma
From the original question, I had understood you wanted to run a script once at a time in the future. Cloud Tasks can do that. However if you want to run it twice at two different times, then you would likely need to register two tasks; one to run at T1 and another to run at T2. - Kolban
How to register the task to run at time T1? Note: The time T1 is configurable through API, not known beforehand. - Ankur Verma
When we create a Task, we can optionally supply a "scheduleTime" ... see cloud.google.com/tasks/docs/reference/rest/v2beta3/… There are APIs for working with Cloud Tasks so one doesn't have to code REST. Probably a good idea to have a read at all the Cloud Task docs. - Kolban

1 Answers

0
votes

In order to schedule a task for a specific dynamic time you can use Google Cloud Task and Google Cloud Functions Read it here: https://cloud.google.com/tasks/docs/tutorial-gcf