Reputation: 11187
I have a connection to a device. Whenever my app shuts down or the connection to the device is lost, I want to update a collection to set it to a state.
function onExit() {
Cylon.observer.stop();
Cylon.connections.update({}, {
$set: { homed: false }
});
}
Meteor.beforeExit(onExit);
Cylon.devices.on('disconnect', onExit);
Would there be a way to create exit hooks in Meteor?
Upvotes: 3
Views: 202
Reputation: 470
You could use this package mizzao:user-status to track the users status and observe your users, for example :
Meteor.users.find({ "status.online": true }).observe({
added: function(id) {
// id just came online
},
removed: function(id) {
// id just went offline
}
});
Upvotes: 0
Reputation: 6173
Meteor application is still an Node.js application, you might consider to use one of the following event listener to do the data update before your application exit
process.on('exit', function() {...})
process.on('uncaughtException', function() {...}}
Upvotes: 4