Registry / devops / cron-cluster

cron-cluster

JSON →
library1.1.3jsnpmunverified

Version 1.1.3. A Redis-based extension of node-cron that ensures jobs run only once across a Node.js cluster, using leader election via redis-leader. Prevents duplicate execution when scaling horizontally. Requires Redis. Last release appears to be 2017 (maintenance mode).

npm install cron-cluster
INSTALL
IMPORT
SIG · CRON-CLUSTER
C
cron-cluster
devopsjavascriptv1.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CronJob
const { CronJob } = require('cron-cluster')(redisClient)
const { CronJob } = require('cron-cluster')
Module exports a function that takes a redis client, returns an object with CronJob.
default export
const createCronCluster = require('cron-cluster'); const { CronJob } = createCronCluster(redisClient)
const CronJob = require('cron-cluster').CronJob
Default export is the factory function.

Initialize cron-cluster with a Redis client, create and start a CronJob that ticks every second.

const redis = require('redis'); const client = redis.createClient(process.env.REDIS_URL ?? ''); const { CronJob } = require('cron-cluster')(client); const job = new CronJob('* * * * * *', () => { console.log('This job runs only once across the cluster'); }, null, true); job.start();
Debug
Known issues
gotchaModule uses require('cron-cluster')(redisClient) — not require('cron-cluster').CronJob directly.
fix
Call the main export as a function passing a redis client.
affects: >=1.0.0
deprecatedPackage has not been updated since 2017. Depends on older node-cron and redis-leader packages.
fix
Consider alternatives like @supercharge/cron or bull with repeatable jobs.
affects: >=1.0.0
gotchaRequires a running Redis instance; no fallback if Redis is down.
fix
Ensure Redis is available or implement circuit breaker.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: require(...) is not a function
Trying to use require('cron-cluster').CronJob directly without calling the exported function.
fix
const { CronJob } = require('cron-cluster')(redisClient)
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
No Redis server running at the default host/port.
fix
Start Redis or configure the client with proper URL.
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies
node-cronrequiredCore cron job functionality
redis-leaderrequiredLeader election mechanism to prevent duplicate jobs
redisrequiredRedis client required (passed by user)
Agent activity
5 hits · last 30 days
node
4
Resources
cron-cluster — npm install cron-cluster · libregistry