Comparing version 0.5.5 to 0.5.6
0.5.6 / 2014-02-18 | ||
================== | ||
* Added failing for jobs with undefined definitions | ||
* Added agenda.purge() to remove old jobs | ||
0.5.5 / 2014-01-28 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -67,2 +67,7 @@ var Job = require('./job.js'), | ||
Agenda.prototype.purge = function(cb) { | ||
var definedNames = Object.keys(this._definitions); | ||
this._db.remove({name: {$not: {$in: definedNames}}}, cb); | ||
}; | ||
Agenda.prototype.define = function(name, options, processor) { | ||
@@ -69,0 +74,0 @@ if(!processor) { |
@@ -119,2 +119,3 @@ var humanInterval = require('human-interval'), | ||
agenda.emit('start:' + self.attrs.name, self); | ||
if(!definition) throw new Error('Undefined job'); | ||
if(definition.fn.length == 2) { | ||
@@ -121,0 +122,0 @@ definition.fn(self, jobCallback); |
{ | ||
"name": "agenda", | ||
"version": "0.5.5", | ||
"version": "0.5.6", | ||
"description": "Light weight job scheduler for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -72,2 +72,3 @@ # Agenda | ||
- [Creating jobs](#creating-jobs) | ||
- [Managing jobs](#managing-jobs) | ||
- [Starting the job processor](#starting-the-job-processor) | ||
@@ -287,2 +288,27 @@ - [Multiple job processors](#multiple-job-processors) | ||
## Managing Jobs | ||
### jobs(mongoskin query) | ||
Lets you query all of the jobs in the agenda job's database. This is a full [mongoskin](https://github.com/kissjs/node-mongoskin) | ||
`find` query. See mongoskin's documentation for details. | ||
```js | ||
agenda.jobs({name: 'printAnalyticsReport'}, function(err, jobs) { | ||
// Work with jobs (see below) | ||
}); | ||
``` | ||
### purge(cb) | ||
Removes all jobs in the database without defined behaviors. Useful if you change a definition name and want to remove old jobs. | ||
*IMPORTANT:* Do not run this before you finish defining all of your jobs. If you do, you will nuke your database of jobs. | ||
```js | ||
agenda.purge(function(err, numRemoved) { | ||
}); | ||
``` | ||
## Starting the job processor | ||
@@ -289,0 +315,0 @@ |
@@ -168,2 +168,19 @@ var mongoCfg = 'localhost:27017/agenda-test', | ||
describe('purge', function() { | ||
it('removes all jobs without definitions', function(done) { | ||
var job = jobs.create('no definition'); | ||
job.save(function() { | ||
jobs.jobs({name: 'no definition'}, function(err, j) { | ||
expect(j).to.have.length(1); | ||
jobs.purge(function() { | ||
jobs.jobs({name: 'no definition'}, function(err, j) { | ||
expect(j).to.have.length(0); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('saveJob', function() { | ||
@@ -291,2 +308,11 @@ it('persists job to the database', function(done) { | ||
}); | ||
it('fails if job is undefined', function(done) { | ||
job = new Job({agenda: jobs, name: 'not defined'}); | ||
job.run(function() { | ||
expect(job.attrs.failedAt).to.be.ok(); | ||
expect(job.attrs.failReason).to.be('Undefined job'); | ||
done(); | ||
}); | ||
}); | ||
it('updates nextRunAt', function(done) { | ||
@@ -293,0 +319,0 @@ var now = new Date(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44105
817
563