Server timer - trigger collection updates in sequence


#1

Hi!

I’m fiddling around and experimenting and found myself building a MVP.

I’m executing code in a time-based sequence. The code posted below will be checked and if requirements are met, triggered every second during a specific date (For example 25th Sep(24 hours)). There will be roughly 200 documents in the collection. How performance heavy will this be? It feels really awkward to iterate the collection every second during a 24h period but it’s necessary for the application to execute the code at a precise moment.

> Server.js
Meteor.startup(function() {
    Meteor.setInterval(function() {
         //THIS CODE WILL BE EXECUTED ON A SPECIFIC DATE AND CONTINUE UNTIL ALL 3 CASES HAVE BEEN FULFILLED
        CollectionHere.find({live: true}).forEach(function (element) {
            switch (element.status) {
                case 1:
                        if(element.timer.start <= 10){
                            CollectionHere.update({_id: element._id, 'timer.start': {$lte: 3599}},
                                                    {$inc: {'timer.start': 1}, $set: {text: 'Waiting..'}},
                                                    {multi: true});
                        }else{
                            //Trigger case 2
                            CollectionHere.update({_id:element._id}, {$set:{status: 2}});
                        }
                    break;
                case 2:
                        if(element.timer.currentTime <= 15){
                                CollectionHere.update({_id: element._id, 'timer.currentTime': {$lte: 5400}},
                                                        {$inc: {'timer.currentTime': 1}, $set: {text: 'ongoing'}},
                                                        {multi: true});
                        }else{
                            CollectionHere.update({_id:element._id}, {$set:{status: 3}});
                        }
                    break;
                case 3:
                        console.log("ALL STEPS EXECUTED");
                        //MIGRATE TO HISTORY COLLECTION AND REMOVE THIS FROM GAME COLLECTION
                    break;
            }
        });
    }, 1000);
});