mohoff
mohoff

Reputation: 321

Periodical MongoDB operations with Meteor

I am building a voting system with Meteor where items can be up- or downvoted. To sort the voting scores more precisely later on, each item holds the fields dailyScore, monthlyScore and alltimeScore, which get incremented or decremented after a vote. I also need to mention, that both registered and unregistered users can vote every 24h (there are two "voters"-arrays containing the userIds of the registered voters and the IP-addresses of the unregistered voters to keep track of the voters and preventing them to vote more than once a day).

The problem I am facing right now is about finding a way to reliably reset

  1. the dailyScore every new day (let's say at UTC-0)
  2. the monthlyScore every new month (in addition to (1.) apparently)
  3. the two voters-arrays on a daily basis (to the same point of time as (1.))


My thoughts so far:

Is there a common pattern or best practice for that? Doing periodical database operations (like every fixed 24h or every new onConnection at a new day) should be a well-known problem.

Upvotes: 0

Views: 61

Answers (1)

Cagdas Can
Cagdas Can

Reputation: 248

percolate:synced-cron package works quite well for this kind of scheduled jobs.

Beware, SyncedCron probably won't work as expected on certain shared hosting providers that shutdown app instances when they aren't receiving requests (like Heroku's free dyno tier or Meteor free galaxy).

Upvotes: 1

Related Questions