I think your application probably lends itself to using a Finite State Machine (FSM) as you go from one state to another depending on events/conditions. I'm busy until the weekend, but as soon as I have a spare moment I'll rough-out some ideas for you. In the meantime, here's a link to a FSM I created for a Block Signalling scheme 'simulation' for the forum member... @Trying_to_learn.
Block Signalling scheme (simulation)
The FSMs are written in Javascript and are located in the 'function' blocks. In your application you would only need one FSM.
Note:
@cflurin created 'node-contrib-dsm' which removes some of the complexity of writing a FSM.