I have a model and I want to set a timer such that after an instance of the model is created, a timer
is counting down for 1 hour. When timer
expires, I want to be able to execute a script. Any ideas?
var mongoose = require ('mongoose');
var Schema = mongoose.Schema;
var mySchema = new Schema({
timer: {
type: Date,
expires: '1h'
}
});
Edit:
Andy here. I'm the creator of the bounty and am not the original poster. I opened this bounty because I haven't figured out a way to confidently track an expiring document. I'm using mongoose-cron to create a job for each user created match. If there are no issues with the server (restarts/crashes/etc.) the cron job expires on time (24 hours) and I set an expired property to false
for the associated document.
The problem is when the server has some sort of interruption. In that case, the cron job is destroyed or—at least—disassociated with the closure I created (feeding in the correct document). Because of this, I don't think cron jobs are the answer and am hoping to find an approach I can trust in production environments.