Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

seneca-node-cron

0.0.2 • Public • Published

Seneca

A Seneca.js cron plugin

seneca-node-cron

npm version Build Status Coverage Status

node-cron plugin for Seneca framework.

For a gentle introduction to Seneca itself, see the senecajs.org site.

Install

To install, simply use npm. Remember you will need to install Seneca.js separately.

npm install seneca
npm install seneca-node-cron

Test

To run tests, simply use npm:

npm run test

Examples

Click here to access the examples

Actions

Create cron job

Create a new cron job

Parameters Type Default Required Description
cronTime String, Date true CronTime accepted by node-cron
tickAction String, Object, Function true Action to be executed on each tick of the job
onJobStop String, Object, Function null Action to be executed when the job is stopped
start Boolean false If true automatically starts the job
timezone String '' Please refer to this for the supported timezones
runOnInit Boolean false If true fire the tickAction immediately after job creation

Examples

seneca.act({ role: 'cron', cmd: 'create' }, {
 cronTime: '* * * * * *',
 tickAction: 'role:hello,cmd:world'
}, (err, response) => {
 console.log(response);
 //{
 //  id: 'ac0094f2-d763-4216-8da9-ddee0a0f9f07',
 //  status: 'created'
 //}
});
seneca.act({ role: 'cron', cmd: 'create' }, {
  cronTime: '* * * * * *',
  tickAction: 'role:hello,cmd:world',
  start: true
}, (err, response) => {
  console.log(response);
  //{
  //  id: 'ac0094f2-d763-4216-8da9-ddee0a0f9f07',
  //  status: 'started'
  //}
});

Start cron job

Start a job matching by id

Parameters Type Default Required Description
id UUID true Id of job

Examples

seneca.act({ role: 'cron', cmd: 'start' }, {
 id: 'ac0094f2-d763-4216-8da9-ddee0a0f9f07'
}, (err, response) => {
 console.log(response);
 //{
 //  id: 'ac0094f2-d763-4216-8da9-ddee0a0f9f07',
 //  status: 'started'
 //}
});

Stop cron job

Stops a job matching by id

Parameters Type Default Required Description
id UUID true Id of job

Examples

seneca.act({ role: 'cron', cmd: 'stop' }, {
 id: 'ac0094f2-d763-4216-8da9-ddee0a0f9f07'
}, (err, response) => {
 console.log(response);
 //{
 //  id: 'ac0094f2-d763-4216-8da9-ddee0a0f9f07',
 //  status: 'stopped'
 //}
});

Remove cron job

Safelly remove a job matching by id, trying to stop it before remove

Parameters Type Default Required Description
id UUID true Id of job

Examples

seneca.act({ role: 'cron', cmd: 'remove' }, {
 id: 'ac0094f2-d763-4216-8da9-ddee0a0f9f07'
}, (err, response) => {
 console.log(response);
 //{
 //  id: 'ac0094f2-d763-4216-8da9-ddee0a0f9f07',
 //  status: 'removed'
 //}
});

Remove all cron jobs

Safelly remove all jobs, trying to stop then before remove

Examples

seneca.act({ role: 'cron', cmd: 'remove', all: true }, (err, response) => {
 console.log(response);
 //{
 //  status: 'cleared',
 //  total: 10
 //}
});

Contributing

The Senecajs org encourage open participation. If you feel you can help in any way, be it with documentation, examples, extra testing, or new features please get in touch.

Install

npm i seneca-node-cron

DownloadsWeekly Downloads

0

Version

0.0.2

License

MIT

Last publish

Collaborators

  • avatar