2.1.1 • Published 8 years ago

batchman v2.1.1

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

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
2.1.1

8 years ago

2.1.0

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.1-3

9 years ago

1.0.1-2

9 years ago

1.0.1-1

9 years ago

1.0.1-0

9 years ago