node-schedule
Advanced tools
Comparing version
@@ -18,2 +18,3 @@ | ||
var anonJobCounter = 0; | ||
var scheduledJobs = {}; | ||
@@ -194,4 +195,4 @@ function isValidDate(date) { | ||
end = spec.end || undefined; | ||
tz = spec.tz; | ||
spec = spec.rule; | ||
tz = spec.tz; | ||
@@ -594,4 +595,2 @@ if (start) { | ||
/* Convenience methods */ | ||
var scheduledJobs = {}; | ||
function scheduleJob() { | ||
@@ -598,0 +597,0 @@ if (arguments.length < 2) { |
{ | ||
"name": "node-schedule", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "A cron-like and not-cron-like job scheduler for Node.", | ||
@@ -15,3 +15,3 @@ "keywords": [ | ||
"test": "nodeunit", | ||
"lint": "eslint lib" | ||
"lint": "eslint lib test" | ||
}, | ||
@@ -34,3 +34,3 @@ "author": { | ||
"coveralls": "^2.11.2", | ||
"eslint": "^0.15.1", | ||
"eslint": "^3.19.0", | ||
"istanbul": "^0.4.5", | ||
@@ -37,0 +37,0 @@ "nodeunit": "^0.10.2", |
@@ -51,4 +51,5 @@ # Node Schedule | ||
first time immediately, so if you create a job using the `scheduleJob()` | ||
convenience method, you'll miss the first `scheduled` event. Also note that | ||
`canceled` is the single-L American spelling. | ||
convenience method, you'll miss the first `scheduled` event, but you can query the | ||
invocation manually (see below). Also note that `canceled` is the single-L American | ||
spelling. | ||
@@ -114,8 +115,2 @@ ### Cron-style Scheduling | ||
You can invalidate the job with the `cancel()` method: | ||
```js | ||
j.cancel(); | ||
``` | ||
To use current data in the future you can use binding: | ||
@@ -205,3 +200,29 @@ | ||
### Handle Jobs and Job Invocations | ||
There are some function to get informations for a Job and to handle the Job and | ||
Invocations. | ||
#### job.cancel(reshedule) | ||
You can invalidate any job with the `cancel()` method: | ||
```js | ||
j.cancel(); | ||
``` | ||
All planned invocations will be canceled. When you set the parameter ***reschedule*** | ||
to true then the Job is newly scheduled afterwards. | ||
#### job.cancelNext(reshedule) | ||
This method invalidates the next planned invocation or the job. | ||
When you set the parameter ***reschedule*** to true then the Job is newly scheduled | ||
afterwards. | ||
#### job.reschedule(spec) | ||
This method cancels all pending invocation and registers the Job completely new again using the given specification. | ||
Return true/false on success/failure. | ||
#### job.nextInvocation() | ||
This method returns a Date object for the planned next Invocation for this Job. If no invocation is planned the method returns null. | ||
## Contributing | ||
@@ -208,0 +229,0 @@ |
@@ -40,28 +40,28 @@ | ||
"Job doesn't emit initial 'scheduled' event": function(test) { | ||
var job = schedule.scheduleJob(new Date(Date.now() + 1000), function() {}); | ||
var job = schedule.scheduleJob(new Date(Date.now() + 1000), function() {}); | ||
job.on('scheduled', function() { | ||
test.ok(false); | ||
}); | ||
job.on('scheduled', function() { | ||
test.ok(false); | ||
}); | ||
setTimeout(function() { | ||
test.done(); | ||
}, 1250); | ||
setTimeout(function() { | ||
test.done(); | ||
}, 1250); | ||
clock.tick(1250); | ||
}, | ||
"Won't run job if scheduled in the past": function(test) { | ||
test.expect(1); | ||
var job = schedule.scheduleJob(new Date(Date.now() - 3000), function() { | ||
test.ok(false); | ||
}); | ||
clock.tick(1250); | ||
}, | ||
"Won't run job if scheduled in the past": function(test) { | ||
test.expect(1); | ||
var job = schedule.scheduleJob(new Date(Date.now() - 3000), function() { | ||
test.ok(false); | ||
}); | ||
test.equal(job, null); | ||
test.equal(job, null); | ||
setTimeout(function() { | ||
test.done(); | ||
}, 1000); | ||
setTimeout(function() { | ||
test.done(); | ||
}, 1000); | ||
clock.tick(1000); | ||
} | ||
clock.tick(1000); | ||
} | ||
}, | ||
@@ -87,40 +87,40 @@ ".scheduleJob(RecurrenceRule, fn)": { | ||
"Job doesn't emit initial 'scheduled' event": function(test) { | ||
/* | ||
* If this was Job#schedule it'd fire 4 times. | ||
*/ | ||
test.expect(3); | ||
/* | ||
* If this was Job#schedule it'd fire 4 times. | ||
*/ | ||
test.expect(3); | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.second = null; // fire every second | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.second = null; // fire every second | ||
var job = new schedule.scheduleJob(rule, function() {}); | ||
var job = new schedule.scheduleJob(rule, function() {}); | ||
job.on('scheduled', function(runOnDate) { | ||
test.ok(true); | ||
}); | ||
job.on('scheduled', function(runOnDate) { | ||
test.ok(true); | ||
}); | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 3250); | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 3250); | ||
clock.tick(3250); | ||
}, | ||
"Doesn't invoke job if recur rule schedules it in the past": function(test) { | ||
test.expect(1); | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.year = 1960; | ||
clock.tick(3250); | ||
}, | ||
"Doesn't invoke job if recur rule schedules it in the past": function(test) { | ||
test.expect(1); | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.year = 1960; | ||
var job = schedule.scheduleJob(rule, function() { | ||
test.ok(false); | ||
}); | ||
test.equal(job, null); | ||
var job = schedule.scheduleJob(rule, function() { | ||
test.ok(false); | ||
}); | ||
test.equal(job, null); | ||
setTimeout(function() { | ||
test.done(); | ||
}, 1000); | ||
setTimeout(function() { | ||
test.done(); | ||
}, 1000); | ||
clock.tick(1000); | ||
} | ||
clock.tick(1000); | ||
} | ||
}, | ||
@@ -145,42 +145,42 @@ ".scheduleJob({...}, fn)": { | ||
"Job doesn't emit initial 'scheduled' event": function(test) { | ||
/* | ||
* With Job#schedule this would be 3: | ||
* scheduled at time 0 | ||
* scheduled at time 1000 | ||
* scheduled at time 2000 | ||
*/ | ||
test.expect(2); | ||
/* | ||
* With Job#schedule this would be 3: | ||
* scheduled at time 0 | ||
* scheduled at time 1000 | ||
* scheduled at time 2000 | ||
*/ | ||
test.expect(2); | ||
var job = schedule.scheduleJob({ | ||
second: null // fire every second | ||
}, function() {}); | ||
var job = schedule.scheduleJob({ | ||
second: null // fire every second | ||
}, function() {}); | ||
job.on('scheduled', function() { | ||
test.ok(true); | ||
}); | ||
job.on('scheduled', function() { | ||
test.ok(true); | ||
}); | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 2250); | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 2250); | ||
clock.tick(2250); | ||
}, | ||
"Doesn't invoke job if object schedules it in the past": function(test) { | ||
test.expect(1); | ||
clock.tick(2250); | ||
}, | ||
"Doesn't invoke job if object schedules it in the past": function(test) { | ||
test.expect(1); | ||
var job = schedule.scheduleJob({ | ||
year: 1960 | ||
}, function() { | ||
test.ok(false); | ||
}); | ||
var job = schedule.scheduleJob({ | ||
year: 1960 | ||
}, function() { | ||
test.ok(false); | ||
}); | ||
test.equal(job, null); | ||
test.equal(job, null); | ||
setTimeout(function() { | ||
test.done(); | ||
}, 1000); | ||
setTimeout(function() { | ||
test.done(); | ||
}, 1000); | ||
clock.tick(1000); | ||
} | ||
clock.tick(1000); | ||
} | ||
}, | ||
@@ -187,0 +187,0 @@ ".scheduleJob({...}, {...}, fn)": { |
@@ -41,3 +41,3 @@ | ||
"UTC": { | ||
"Should accept a valid UTC date in milliseconds": function(test) { | ||
"Should accept a valid UTC date in milliseconds": function(test) { | ||
test.expect(1); | ||
@@ -44,0 +44,0 @@ |
@@ -202,43 +202,43 @@ | ||
"Job emits 'scheduled' event for every next invocation": function(test) { | ||
// Job will run 3 times but be scheduled 4 times, 4th run never happens | ||
// due to cancel. | ||
test.expect(4); | ||
// Job will run 3 times but be scheduled 4 times, 4th run never happens | ||
// due to cancel. | ||
test.expect(4); | ||
var job = new schedule.Job(function() {}); | ||
var job = new schedule.Job(function() {}); | ||
job.on('scheduled', function(runOnDate) { | ||
test.ok(true); | ||
}); | ||
job.on('scheduled', function(runOnDate) { | ||
test.ok(true); | ||
}); | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.second = null; // fire every second | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.second = null; // fire every second | ||
job.schedule(rule); | ||
job.schedule(rule); | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 3250); | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 3250); | ||
clock.tick(3250); | ||
}, | ||
"Doesn't invoke job if recur rule schedules it in the past": function(test) { | ||
test.expect(0); | ||
clock.tick(3250); | ||
}, | ||
"Doesn't invoke job if recur rule schedules it in the past": function(test) { | ||
test.expect(0); | ||
var job = new schedule.Job(function() { | ||
test.ok(false); | ||
}); | ||
var job = new schedule.Job(function() { | ||
test.ok(false); | ||
}); | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.year = 2000; | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.year = 2000; | ||
job.schedule(rule); | ||
job.schedule(rule); | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 1000); | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 1000); | ||
clock.tick(1000); | ||
} | ||
clock.tick(1000); | ||
} | ||
}, | ||
@@ -265,41 +265,41 @@ "#schedule({...})": { | ||
"Job emits 'scheduled' event for every next invocation": function(test) { | ||
// Job will run 3 times but be scheduled 4 times, 4th run never happens | ||
// due to cancel. | ||
test.expect(4); | ||
// Job will run 3 times but be scheduled 4 times, 4th run never happens | ||
// due to cancel. | ||
test.expect(4); | ||
var job = new schedule.Job(function() {}); | ||
var job = new schedule.Job(function() {}); | ||
job.on('scheduled', function(runOnDate) { | ||
test.ok(true); | ||
}); | ||
job.on('scheduled', function(runOnDate) { | ||
test.ok(true); | ||
}); | ||
job.schedule({ | ||
second: null // Fire every second | ||
}); | ||
job.schedule({ | ||
second: null // Fire every second | ||
}); | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 3250); | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 3250); | ||
clock.tick(3250); | ||
}, | ||
"Doesn't invoke job if object schedules it in the past": function(test) { | ||
test.expect(0); | ||
clock.tick(3250); | ||
}, | ||
"Doesn't invoke job if object schedules it in the past": function(test) { | ||
test.expect(0); | ||
var job = new schedule.Job(function() { | ||
test.ok(false); | ||
}); | ||
var job = new schedule.Job(function() { | ||
test.ok(false); | ||
}); | ||
job.schedule({ | ||
year: 2000 | ||
}); | ||
job.schedule({ | ||
year: 2000 | ||
}); | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 1000); | ||
setTimeout(function() { | ||
job.cancel(); | ||
test.done(); | ||
}, 1000); | ||
clock.tick(1000); | ||
} | ||
clock.tick(1000); | ||
} | ||
}, | ||
@@ -306,0 +306,0 @@ "#schedule('jobName', {...})": { |
@@ -305,9 +305,9 @@ | ||
rule.month = 12; | ||
var next = rule.nextInvocationDate(next); | ||
var next = rule.nextInvocationDate(); | ||
test.equal(next, null); | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.month = 'asdfasdf'; | ||
next = rule.nextInvocationDate(next); | ||
test.equal(next, null); | ||
var rule2 = new schedule.RecurrenceRule(); | ||
rule2.month = 'asdfasdf'; | ||
var next2 = rule2.nextInvocationDate(next); | ||
test.equal(next2, null); | ||
@@ -319,9 +319,9 @@ test.done(); | ||
rule.second = 60; | ||
var next = rule.nextInvocationDate(next); | ||
var next = rule.nextInvocationDate(); | ||
test.equal(next, null); | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.second = 'asdfasdf'; | ||
next = rule.nextInvocationDate(next); | ||
test.equal(next, null); | ||
var rule2 = new schedule.RecurrenceRule(); | ||
rule2.second = 'asdfasdf'; | ||
var next2 = rule2.nextInvocationDate(); | ||
test.equal(next2, null); | ||
@@ -333,9 +333,9 @@ test.done(); | ||
rule.hour = 24; | ||
var next = rule.nextInvocationDate(next); | ||
var next = rule.nextInvocationDate(); | ||
test.equal(next, null); | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.hour = 'asdfasdf'; | ||
next = rule.nextInvocationDate(next); | ||
test.equal(next, null); | ||
var rule2 = new schedule.RecurrenceRule(); | ||
rule2.hour = 'asdfasdf'; | ||
var next2 = rule2.nextInvocationDate(); | ||
test.equal(next2, null); | ||
@@ -347,16 +347,16 @@ test.done(); | ||
rule.date = 90; | ||
var next = rule.nextInvocationDate(next); | ||
var next = rule.nextInvocationDate(); | ||
test.equal(next, null); | ||
// Test February | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.month = 1; | ||
rule.date = 30; | ||
next = rule.nextInvocationDate(next); | ||
test.equal(next, null); | ||
var rule2 = new schedule.RecurrenceRule(); | ||
rule2.month = 1; | ||
rule2.date = 30; | ||
var next2 = rule2.nextInvocationDate(); | ||
test.equal(next2, null); | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.date = 'asdfasdf'; | ||
next = rule.nextInvocationDate(next); | ||
test.equal(next, null); | ||
var rule3 = new schedule.RecurrenceRule(); | ||
rule3.date = 'asdfasdf'; | ||
var next3 = rule3.nextInvocationDate(); | ||
test.equal(next3, null); | ||
@@ -368,9 +368,9 @@ test.done(); | ||
rule.dayOfWeek = 90; | ||
var next = rule.nextInvocationDate(next); | ||
var next = rule.nextInvocationDate(); | ||
test.equal(next, null); | ||
var rule = new schedule.RecurrenceRule(); | ||
rule.dayOfWeek = 'asdfasdf'; | ||
next = rule.nextInvocationDate(next); | ||
test.equal(next, null); | ||
var rule2 = new schedule.RecurrenceRule(); | ||
rule2.dayOfWeek = 'asdfasdf'; | ||
var next2 = rule.nextInvocationDate(); | ||
test.equal(next2, null); | ||
@@ -377,0 +377,0 @@ test.done(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
80220
1.14%250
9.17%