copleykj / socialize-server-presence

A Meteor package to keep track of your running app instances and help you clean up the mess when they fail.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ServerPresence.onCleanup not always being called

heyiamben opened this issue · comments

ServerPresence.onCleanup was not always being called when meteor was killed and then restarted.

We fixed this by changing the observe function

var observe = function(){
    var self = this;
    observeHandle = Servers.find().observe({
        removed: function(document){
            if(document._id === serverId){
                if(!isWatcher){
                    throw new Meteor.Error("Server Presence Timeout", "The server-presence package has detected inconsistent presence state. To avoid inconsistent database state your application is exiting.");
                    process.exit();
                }else{
                    insert();
                }
            }else if(isWatcher){
                if(!document.graceful){
                    runCleanupFunctions(document._id);
                }
            }else if(document.watcher){
                if(!document.graceful){
                    runCleanupFunctions(document._id);                //Cleanup here as well
                }
                updateWatcher();
            }
        }
    });
};

This is great.. I had just mentioned that this was broken in an issue on socialize:user-presence the other day, but hadn't gotten around to take a look at the problem. Thanks for this.