Best practice ? How to trigger an event when timestamp of a field reaches now()


Hello everyone,

I have a collection with a particular field “end_time” which is a timestamp. I would like to find the best way to trigger an action while this timestamps passes the now() time.

I have some ideas but would very much enjoy some leads :

  • Using CRON package ? I don’t really know how they work yet, but it seems it has some similarities with my problem ? Could you confirm ? recommend a particular package ?

  • Looping a method on server : I was thinking to loop a method (every minute for example) through all my collection and each time the timestamp has passed the field timestamp, and the action has not yet beeing called, it will trigger it. I am bit scared of the ressources it may use. Also if once there is a probleme with the script or data, isn’t there a risk it’ll stop fully the script and never restart it until I restart server ?

  • Ideally I would kind of need a tracker, that would track the end_time timestamp of my collection ? Is it doable ? any leads ?

A bit lost here to be honest, hoping to read from you guys.


This is a good strategy, especially if the end time is fixed for a document (management becomes harder if you allow the end time to be changed). Packages to consider are percolate:synced-cron and msavin:sjobs, although there are many as you’ve probably found! You would probably set up the cron and store its _id in your document for cross-referencing.

Yes - I’d be equally wary about doing that in server code. It could end up very costly and if you ever scale-out your application, you may need to ensure that only one instance was managing any one end time.