batchman

2.1.1 • Public • Published

Batchman

Worker process scheduler which takes a file and cron pattern and runs in a Docker container.

To implement a job create a new Dockerfile and inherit from gimanzo/batchman:

Create the Dockerfile

FROM gimanzo/batchman

ADD package.json /app/package.json
RUN cd /app && npm install --production --unsafe-perm

ADD . /app

CMD cd /app/ && \
    pm2 start app.js -f -- -j ./job.js && \
    pm2 logs

Create the app.js file

How easy could it be - just reference batchman and you're done!

 require('batchman');

Create the job

In the job file job.js implement the job as in the following example:

var JobBase = require('batchman').JobBase;
var util = require('util');
var fs = require('fs');
var path = require('path');

var SampleJob = function () {
    JobBase.call(this);
    this.name = 'daily_mailer';
};
util.inherits(SampleJob, JobBase);

function sendEmail(that) {
    that.emit(that.eventNames.progress, {name: 'mailing'});
    that.emit(that.eventNames.end);
}

SampleJob.prototype.execute = function () {
    var that = this;
    that.emit(that.eventNames.start, 'Starting');
    sendEmail(that);
    return that;
};
exports.Job = SampleJob;

Finally build and run the container

docker build -t [myrepo]/report_worker:latest .

docker run -e "BATCHMAN_CRON_PATTERN=*/5 * * * * *" [myrepo]/report_worker

Readme

Keywords

none

Package Sidebar

Install

npm i batchman

Weekly Downloads

1

Version

2.1.1

License

MIT

Last publish

Collaborators

  • gimanzo