Skip to content

Commit

Permalink
Update README.md with reasonable config
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguydan committed May 19, 2013
1 parent cf14b8f commit a9d2ef2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
34 changes: 33 additions & 1 deletion README.md
@@ -1,7 +1,39 @@
delayed-job
===========
delayed-job is a horizontally scalable implementation of Ruby's delayed_job. Using semaphore locks it aims to provide an atomic interface to workers. Initial work has focussed on a Redis backed database, however more are possible.

## Assumptions
# Installation

```npm install delayed-job```

# Usage
```
var Scheduler = require('../index.js');
var scheduler = Scheduler.createScheduler({
backend: {
name: 'redis',
jobHoldingBay: 'myUniqueListKey'
}
});
scheduler.on('job',function(job) {
console.log('Received job',job);
});
var myJob = {
title: 'Great Gig In The Sky'
};
scheduler.delay(myJob,2000);
```

# API

## schedular.delay(job,timeout)
Schedule a job for execution

# Assumptions
* errors thrown will result in re-establishing the scheduler [expand]
* Single atomic source of truth
* Db interactions are also atomic
Expand Down
7 changes: 6 additions & 1 deletion examples/simple.js
@@ -1,6 +1,11 @@
var Scheduler = require('../index.js');

var scheduler = Scheduler.createScheduler();
var scheduler = Scheduler.createScheduler({
backend: {
name: 'redis',
jobHoldingBay: 'myUniqueListKey'
}
});

scheduler.on('job',function(job) {
console.log('Received job',job);
Expand Down
3 changes: 1 addition & 2 deletions lib/Scheduler.js
Expand Up @@ -20,8 +20,7 @@ function Scheduler(opts) {

// Check whether a backend was provided
if (opts.backend) {
var db = path.resolve('./db',opts.backend.name+'.js');
this._backend = db.createDB(opts.backend);
this._backend = require('./db/'+opts.backend.name).createDB(opts.backend);
}
else {
this._backend = require('./db/redis.js').createDB();
Expand Down
10 changes: 7 additions & 3 deletions lib/db/redis.js
Expand Up @@ -2,14 +2,18 @@ var redis = require('redis-url');
var async = require('async');

exports.createDB = function(opts) {
return new DB(opts)
return new DB(opts.url || null);
};

function DB(opts) {
// TODO figure out opts

// TODO figure out opts
this._conn = redis.connect(opts);

opts = opts || {};

this._holdingListKey = opts.jobHoldingBay || 'holdingListKey';
this._semaphorName = ['delayed',Math.round(Math.random()*100)].join(':');
this._holdingListKey = ['holdingListKey',Math.round(Math.random()*100)].join(':');
}

DB.prototype.lock = function(fn) {
Expand Down

0 comments on commit a9d2ef2

Please sign in to comment.