0.0.2 • Published 8 years ago

seneca-node-cron v0.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

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

ParametersTypeDefaultRequiredDescription
cronTimeString, DatetrueCronTime accepted by node-cron
tickActionString, Object, FunctiontrueAction to be executed on each tick of the job
onJobStopString, Object, FunctionnullAction to be executed when the job is stopped
startBooleanfalseIf true automatically starts the job
timezoneString''Please refer to this for the supported timezones
runOnInitBooleanfalseIf 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

ParametersTypeDefaultRequiredDescription
idUUIDtrueId 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

ParametersTypeDefaultRequiredDescription
idUUIDtrueId 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

ParametersTypeDefaultRequiredDescription
idUUIDtrueId 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.