Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you implement periodically executing job?

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.

like image 467
Junpei Tajima Avatar asked May 23 '14 13:05

Junpei Tajima


Video Answer


1 Answers

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.

like image 110
dylants Avatar answered Sep 21 '22 15:09

dylants