Run Cron Jobs After The Node Server Restarts (volatility, Recoverability, Durability)
Solution 1:
As you mentioned, you'd have to record it as "done" in some way.
I don't believe the cron
package provides any way to do that directly.
There are a number of ways. If you are already using a database which has user-specific data, that would definitely be the most logical place to store it.
Another option would be to store it in a flat file of some sort.
Another approach could be to have a queue that would read jobs off as it completes them.
As the users sign up, you would add a record for them to the bottom of the queue, probably along with a timestamp since there is substantial delay until it is run. This would mean the queue would be in chronological order, with the soonest item at the top, latest at the bottom.
The tech behind the queue would be somewhat irrelevant. It could be as simple as a plaintext file, or something sophisticated like a Kafka queue
Then your program could look at the first line of the queue every so often. If that item is ready to go, do whatever you need to do, then remove it from the queue. If not, just leave it alone and check it again in a little while.
This way, the item is still in the queue until it is done, and even if your program is shutdown when it's time to fire, it'll still fire when it starts back up.
Solution 2:
So I've implemented this in this project: crone-durability
Post a Comment for "Run Cron Jobs After The Node Server Restarts (volatility, Recoverability, Durability)"