Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cron-cluster

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cron-cluster - npm Package Compare versions

Comparing version 1.0.0 to 1.1.3

test/cron-cluster-compatibilty-check.js

42

lib/cron-cluster.js

@@ -0,5 +1,3 @@

var wrap = require('lodash/wrap')
var wrap = require('lodash.wrap')
var toArray = require('lodash.toarray')
var OriginCronJob = require('cron').CronJob

@@ -18,22 +16,34 @@ var Leader = require('redis-leader')

function CronJob (cronTime, onTick) {
if (typeof cronTime !== 'string' && arguments.length === 1) {
onTick = cronTime.onTick
function CronJob (cronSettings, onTick, onComplete, start, timeZone) {
if (typeof cronSettings === 'string') {
cronSettings = {cronTime: cronSettings}
}
if (onTick) {
cronSettings.onTick = onTick
}
if (onComplete) {
cronSettings.onComplete = onComplete
}
if (start) {
cronSettings.start = start
}
if (timeZone) {
cronSettings.timeZone = timeZone
}
this.started = false
// Wrap `onTick` for checking if is leader
onTick = wrap(onTick, function (fn) {
cronSettings.onTick = wrap(cronSettings.onTick, function (fn) {
logger('On tick')
leader.isLeader(function (err, isLeader) {
if (err) return fn(err)
logger('On tick: leader = %s', isLeader)
if (!isLeader) return
fn()
})
setTimeout(function () {
leader.isLeader(function (err, isLeader) {
if (err) return fn(err)
logger('On tick: leader = %s', isLeader)
if (!isLeader) return
fn()
})
}, 50)
})
// Create real CronJob
var args = toArray(arguments)
args.unshift({})
var job = new (Function.bind.apply(OriginCronJob, args))
var job = new (OriginCronJob.bind([], cronSettings))
// Wrap `stop` for stopping leader before

@@ -40,0 +50,0 @@ job.stop = wrap(job.stop, function (stop) {

{
"name": "cron-cluster",
"version": "1.0.0",
"version": "1.1.3",
"description": "A Cluster version of node-cron using redis",

@@ -25,6 +25,5 @@ "main": "index.js",

"dependencies": {
"cron": "^1.0.9",
"debug": "^2.2.0",
"lodash.toarray": "^3.0.2",
"lodash.wrap": "^3.0.1",
"cron": "^1.2.1",
"debug": "^2.6.0",
"lodash": "^4.17.11",
"redis-leader": "^0.1.0"

@@ -38,3 +37,6 @@ },

"tape": "^4.2.0"
},
"engines": {
"node": ">=4"
}
}

@@ -35,2 +35,20 @@ # Cron-cluster

It is possible to initialize CronJob with an object passed as parameter and run the job only once for all the instances.
Cron-cluster is compatible with original cron. More in test/cron-cluster-compatibility-check.js
```js
var redis = require('redis').createClient()
var CronJob = require('cron-cluster')(redis).CronJob
function doCron () {
var job = new CronJob({
cronTime: '* * * * * *',
onTick: function () {
// Do some stuff here
}
})
job.start()
}
```
All you need is to provide a redis client to the cron-cluster module.

@@ -37,0 +55,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc