-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feature) add redis options with leader election over redis for CronJob
- Loading branch information
0 parents
commit 901b216
Showing
6 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: nodejs | ||
nodejs: | ||
- iojs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('./lib/cron-cluster') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
var _ = require('lodash') | ||
var OriginCronJob = require('cron').CronJob | ||
var Leader = require('redis-leader') | ||
|
||
module.exports = function (redis) { | ||
var leader = new Leader(redis) | ||
|
||
return { | ||
CronJob: CronJob | ||
} | ||
|
||
function CronJob (cronTime, onTick) { | ||
if (typeof cronTime !== 'string' && arguments.length === 1) { | ||
onTick = cronTime.onTick | ||
} | ||
|
||
onTick = _.wrap(onTick, function (fn) { | ||
leader.isLeader(function (isLeader) { | ||
if (!isLeader) return | ||
fn() | ||
}) | ||
}) | ||
|
||
return new (OriginCronJob.bind.apply(OriginCronJob, arguments)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "cron-cluster", | ||
"version": "0.0.1", | ||
"description": "A Cluster plugin for cron using redis", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"test": "tap test/*.js | faucet" | ||
}, | ||
"author": "Andy Vanbutsele <[email protected]>", | ||
"license": "ISC", | ||
"dependencies": { | ||
"cron": "^1.0.9", | ||
"lodash": "^3.10.1", | ||
"redis-leader": "^0.1.0" | ||
}, | ||
"devDependencies": { | ||
"faucet": "0.0.1", | ||
"tap": "^1.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var test = require('tap').test | ||
|
||
test('Should do something', function (t) { | ||
t.plan(1) | ||
t.equal(1, 1, '1 == 1') | ||
}) |