Reputation: 1404
My application is hosted in firebase. It is an angular application with a firestore database. I currently have a scenario where I need to check if something has expired and then act upon it. For this I currently have a node application running in an app engine which has a cron job scheduled that runs every 2 seconds to poll the firestore database for a collection and see if the expiration time is older than the current time and then it performs the intended task.
cron.schedule("*/2 * * * * *", fn => {
// code here for intended task
}
Because of this 2 second cron job I have to have to maintain an instance on app engine. I was trying to see if I can use the cloud scheduler to schedule a job so that I can save some money by not having an instance in app engine.
But the cloud scheduler's granularity is only till every 1 minute and I am looking for granularity in seconds so that I can schedule a job to run every 2 seconds. Is there a way that I can achieve this without having to host an application on app engine.
Upvotes: 2
Views: 2365
Reputation: 39834
Polling in general is rather wasteful, if at all possible try to replace it with something better.
In your case, for example, as soon as the expiration time is set you can also determine the exact time when the intended task is supposed to be executed (i.e. the moment your're trying to determine with polling).
In (1st generation standard environment) app engine I'd simply enqueue the intended task as a delayed push task queue item. Either as an absolute value or one relative to the current time. No need for polling, the task will be executed whenever its eta arrives.
I'm not familiar with angular/firebase, but it appears to me that the Angular Task Service API is pretty similar.
Upvotes: 1