How do you implement periodically executing job?

Junpei Tajima picture Junpei Tajima · May 23, 2014 · Viewed 8.1k times · Source

I am recently implementing a system that automatically replies to tweets that contain arbitrary hashtags. This system consists of a process that periodically crawls Twitter and a process that periodically replies to these tweets. Following the tradition of my company, these periodical jobs are implemented with working tables on RDMS that have a status column which would have values like "waiting", "processing" or "succeed". To ensure redundancy, I make multiple same processes running by leveraging low level locks.

My question is, I'm implementing periodically jobs with working tables in RDMS, how these jobs are implemented in generally.

Answer

dylants picture dylants · May 23, 2014

There's a node package cron which allows you to execute code at some specified interval, just like crontab. Here's a link to the package: https://www.npmjs.org/package/cron

For example:

var cronJob = require("cron").CronJob;

// Run this cron job every Sunday (0) at 7:00:00 AM
new cronJob("00 00 7 * * 0", function() {
    // insert code to run here...
}, null, true);

You might be able to use that module to run some job periodically, which crawls twitter or replies to tweets.