7

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.

DrCord
  • 3,917
  • 3
  • 34
  • 47
Junpei Tajima
  • 310
  • 1
  • 4
  • 11

1 Answers1

12

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.

dylants
  • 22,316
  • 3
  • 26
  • 22
  • 4
    Apart from the capability of controlling when is the function executed, are there other benefits of this solution over the native `setInterval`? – kiril Dec 01 '16 at 04:59
  • 3
    I was interested in same, so found this for you: https://stackoverflow.com/questions/18120909/set-interval-in-node-js-vs-cron-job – pegla Sep 12 '17 at 07:28