Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

agenda

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

agenda - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

11

History.md
n.n.n / 2013-11-19
0.4.0 / 2013-12-04
==================
* Fixed for setImmediate on Node 0.8
* updated README
* Added Cron Support [Closes #2]
* removed modella dependency
0.3.1 / 2013-11-19
==================
* Fix for setImmediate on Node 0.8
0.3.0 / 2013-11-19

@@ -9,0 +14,0 @@ ==================

@@ -79,6 +79,6 @@ var Job = require('./job.js'),

this._definitions[name] = {
fn: processor,
concurrency: options.concurrency || this._defaultConcurrency,
priority: options.priority || 0,
running: 0
fn: processor,
concurrency: options.concurrency || this._defaultConcurrency,
priority: options.priority || 0,
running: 0
};

@@ -85,0 +85,0 @@ };

var humanInterval = require('human-interval'),
CronTime = require('cron').CronTime,
date = require('date.js');

@@ -26,6 +27,24 @@

Job.prototype.computeNextRunAt = function() {
var interval = this.attrs.repeatInterval;
if(interval) {
// Check if its a cron string
var lastRun = this.attrs.lastRunAt || new Date();
try {
var cronTime = new CronTime(interval);
var nextDate = cronTime._getNextDateFrom(lastRun);
this.attrs.nextRunAt = nextDate;
} catch(e) {
// Nope, humanInterval then!
this.attrs.nextRunAt = lastRun.valueOf() + humanInterval(interval);
}
} else {
this.attrs.nextRunAt = undefined;
}
return this;
};
Job.prototype.repeatEvery = function(interval) {
this.attrs.repeatInterval = humanInterval(interval);
this.attrs.repeatInterval = interval;
return this;

@@ -62,7 +81,3 @@ };

self.attrs.lastRunAt = now;
if(self.attrs.repeatInterval) {
self.attrs.nextRunAt = new Date(now.valueOf() + self.attrs.repeatInterval);
} else {
self.attrs.nextRunAt = undefined;
}
self.computeNextRunAt();
try {

@@ -69,0 +84,0 @@ definition.fn(self, function() {

{
"name": "agenda",
"version": "0.3.1",
"version": "0.4.0",
"description": "Light weight job scheduler for Node.js",

@@ -20,2 +20,3 @@ "main": "index.js",

"jobs",
"cron",
"delayed",

@@ -31,7 +32,6 @@ "scheduler",

"dependencies": {
"modella": "~0.1.7",
"modella-mongo": "~0.1.4",
"human-interval": "0.1.1",
"date.js": "~0.1.1",
"mongoskin": "~0.6.0"
"mongoskin": "~0.6.0",
"cron": "~1.0.1"
},

@@ -38,0 +38,0 @@ "devDependencies": {

@@ -12,3 +12,4 @@ # Agenda

- Mongo backed persistance layer.
- Scheduling with priority, repeating, and easily readable syntax.
- Scheduling with configurable priority, concurrency, and repeating
- Scheduling via cron or human readable syntax.
- Event backed job queue that you can hook into.

@@ -33,2 +34,6 @@

// Alternatively, you could also do:
agenda.every('*/3 * * * *', 'delete old users');
agenda.start();

@@ -197,2 +202,4 @@ ```

`interval` can be a human-readable format `String`, a cron format `String`, or a `Number`.
`data` is an optional argument that will be passed to the processing function

@@ -237,3 +244,5 @@ under `job.data`.

var job = agenda.create('printAnalyticsReport', {userCount: 100});
job.save();
job.save(function(err) {
console.log("Job successfully saved");
});
```

@@ -267,2 +276,4 @@

`interval` can be a human-readable format `String`, a cron format `String`, or a `Number`.
```js

@@ -318,3 +329,5 @@ job.repeatEvery('10 minutes');

```js
job.save()
job.save(function(err) {
if(!err) console.log("Successfully saved job to collection");
})
```

@@ -328,2 +341,3 @@

- `complete:job name` - called when a job finishes, regardless of if it succeeds or fails
```js

@@ -333,4 +347,4 @@ agenda.on('complete', function(job) {

});
```
```
- `success` - called when a job finishes successfully

@@ -352,2 +366,3 @@ - `success:job name` - called when a job finishes successfully

});
```

@@ -354,0 +369,0 @@ ## Frequently Asked Questions

@@ -118,3 +118,3 @@ var expect = require('expect.js'),

it('sets the repeatEvery', function() {
expect(jobs.every('5 seconds', 'send email').attrs.repeatInterval).to.be(5000);
expect(jobs.every('5 seconds', 'send email').attrs.repeatInterval).to.be('5 seconds');
});

@@ -187,2 +187,3 @@ it('sets the agenda', function() {

describe('priority', function() {
var job;
beforeEach(function() {

@@ -204,2 +205,39 @@ job = new Job();

describe.only('computeNextRunAt', function() {
var job;
beforeEach(function() {
job = new Job();
});
it('returns the job', function() {
expect(job.computeNextRunAt()).to.be(job);
});
it('sets to undefined if no repeat interval', function() {
job.computeNextRunAt();
expect(job.attrs.nextRunAt).to.be(undefined);
});
it('it understands human intervals', function() {
var now = new Date();
job.attrs.lastRunAt = now;
job.repeatEvery('2 minutes');
job.computeNextRunAt();
expect(job.attrs.nextRunAt).to.be(now.valueOf() + 120000);
});
it('understands cron intervals', function() {
var now = new Date();
now.setMinutes(1);
now.setMilliseconds(0);
now.setSeconds(0);
job.attrs.lastRunAt = now;
job.repeatEvery('*/2 * * * *');
job.computeNextRunAt();
expect(job.attrs.nextRunAt.valueOf()).to.be(now.valueOf() + 60000);
});
});
describe('run', function() {

@@ -206,0 +244,0 @@ var job,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc