Reputation: 41
I'm looking for a way to fire a service at a specific time in SailsJS. In this case, I have an Event
model which includes two attributes: a boolean
which is default to be false and a datetime
which is assigned whenever an event is created. Also, there is an endEvent
service to be fired according to the datetime
.
I want my whole process be like, for every created event:
boolean
attribute to false.datetime
into a future time.datetime
which set the boolean
attribute from false to true.My model:
// Event.js
module.exports = {
attributes: {
end: {
type: 'boolean'
},
deadline: {
type: 'datetime'
}
}
}
My service:
// endEvent.js
module.exports = {
setEnd: function(event) {
Event.findOne(event).exec(function (err, result) {
result.end = true;
result.save();
});
}
};
However I cannot find the proper way to run a service in a specific time.
Thanks in advance for your help!
Upvotes: 0
Views: 157
Reputation: 5871
sailsjs
has no support for task scheduling out of the box. You will have to use a package like node-cron
or agenda
or kue
and build your own solution. Also, there is a sails hook, sails-hook-schedule
which you can try out.
Upvotes: 1