Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Persist setTimeout and setInterval across Node.js restarts

Persist setTimeout and setInterval across Node.js restarts

Problem

I set quite a few server-side timeouts with Settimeout and setInterval for each connected user that can last for 10-30 seconds. If the Node.js instance restarts in the middle of one of these timeouts, they are obviously all cleared on restart, which can cause some issues for these users. How would I go about persisting these timeouts, or are there any modules that already help with this?

Problem courtesy of: James Simpson

Solution

I would store the start times and durations in Redis and restart incomplete timers when your application reloads. Some Redis modules:

https://github.com/joyent/node/wiki/modules#wiki-db-nosql-redis

Solution courtesy of: Loc Nguyen

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Persist setTimeout and setInterval across Node.js restarts

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×