Giter Site home page Giter Site logo

joba's Introduction

joba

Simple job (task) scheduler (manager).

Installation

npm install joba --save

Depending on your choice you should also install bus and persistence dependencies (for example, joba-worque, joba-pg).

Example

Task manager module.

var Joba = require('joba');

var manager = new Joba({
	persistence: {
		name: 'pg',
		connection: {
			uri: 'postgresql://user:password@server/db',
			table: 'tasks'
		}
	},
	bus: {
		name: 'worque',
		connection: {
			host: 'server',
			login: 'user',
			password: 'password'
		}
	}
});

module.exports = manager;

Scheduler app.

var manager = require('./manager');

manager.schedule('* */2 * * *', 'scan web');

Worker app.

var manager = require('./manager');

manager.handle('scan web', scanWeb, true);

function scanWeb () {
	var profitPromise;
	// do something
	return profitPromise;
}

It's recommended to split your task handling process into 2 parts: scheduling and processing and run them into separate applications. It will allow you to restart worker app on failure without loosing the schedule or task being processed while failure has happened.

API

Joba(options)

Constructs manager instance. Accepts 2 options: bus and persistence configuration (see example).

schedule(cronTime, name[, params])

Schedules task execution.

start(name[, params])

Starts immediate task execution.

handle(name, handler[, exitOnFailure][, logParams])

Deprecated (use overload with options as last param).

Specifies task handler. If exitOnFailure is true, then app will exit with code 75 (temporary failure), allowing you to implement restart-on-error management policy for worker app. If logParams is true then params will be saved in the corresponding work log record, if logParams is omitted, then logging will happen only on error, otherwise (if logParams === false) no logging will happen at all.

handle(name, handler[, options])

Specifies task handler.

Options:

name purpose
exitOnFailure if true, then app will exit with code 75 (temporary failure), allowing you to implement restart-on-error management policy for worker app
logParams if true then params will be saved in the corresponding work log record, if omitted, then logging will happen only on error, otherwise (if false) no logging will happen at all
concurrency maximal number of tasks handled simultaneously

pipe(source, destination)

Passes output of one task to input(s) of another task(s).

If destination is string:

source -> destination

otherwise, if destination is object and destination.opcode is map:

source[0] -> destination.names[0]
source[1] -> destination.names[0]
source[2] -> destination.names[0]
...

and if destination.opcode is spread:

source[0] -> destination.names[0]
source[1] -> destination.names[1]
source[2] -> destination.names[2]
...

License

BSD

joba's People

Contributors

titarenko avatar

Stargazers

BJR Matos avatar  avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.