Skip to content

Commit 29539d1

Browse files
committed
Merge pull request #4 from qubyte/chore/test-updates
Test updates and a minor API change to make add and remove methods return the relevant job.
2 parents 53298a2 + e52f020 commit 29539d1

File tree

8 files changed

+261
-286
lines changed

8 files changed

+261
-286
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Add a job. The `time` must be a date object or a timestamp integer (like `Date.n
9090

9191
### `var job = rb.remove(hash)`
9292

93-
Remove a job from a Rubidium instance with the job hash. This function returns the job if it existed and was removed, and `undefined` if the job did not exist.
93+
Remove a job from a Rubidium instance with the job hash. This function returns a job if the job existed and was removed, or `undefined` if the job did not exist.
9494

9595
### `var job = rb.find(hash)`
9696

examples/at-server.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
var express = require('express');
24
var request = require('request');
35
var Rubidium = require('../');
@@ -9,16 +11,12 @@ app.use(express.json());
911

1012
// In this case, the body is the message and it includes a callback URL.
1113
app.post('/add/:timestamp', function (req, res) {
12-
'use strict';
13-
1414
rb.add(parseInt(req.params.timestamp, 10), req.body);
1515
res.send(202);
1616
});
1717

1818
// When the job is emitted, send it back to the callback URL.
1919
rb.on('job', function (job) {
20-
'use strict';
21-
2220
var req;
2321

2422
// Protect against 'Invalid Request' errors.

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
'use strict';
2+
13
module.exports = require('./lib/Rubidium');

lib/Job.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var crypto = require('crypto');
24
var stringify = require('json-stable-stringify');
35

@@ -10,8 +12,6 @@ var stringify = require('json-stable-stringify');
1012
*/
1113

1214
function Job(time, message) {
13-
'use strict';
14-
1515
if (!(this instanceof Job)) {
1616
return new Job(time, message);
1717
}
@@ -38,8 +38,6 @@ function Job(time, message) {
3838
*/
3939

4040
Job.prototype.stringify = function () {
41-
'use strict';
42-
4341
return stringify({ time: this.time, message: this.message });
4442
};
4543

@@ -52,8 +50,6 @@ Job.prototype.stringify = function () {
5250
*/
5351

5452
Job.fromList = function (specs) {
55-
'use strict';
56-
5753
var jobs = [];
5854

5955
for (var i = 0, len = specs.length; i < len; i++) {

lib/Rubidium.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var EventEmitter = require('events').EventEmitter;
24
var util = require('util');
35

@@ -11,8 +13,6 @@ var Job = require('./Job');
1113
*/
1214

1315
function makeTimeout(rubidium) {
14-
'use strict';
15-
1616
// > 0 is in the future.
1717
var dt = Math.max(rubidium.jobs[0].time - Date.now(), 0);
1818

@@ -32,8 +32,6 @@ function makeTimeout(rubidium) {
3232
*/
3333

3434
function makeNext(rubidium) {
35-
'use strict';
36-
3735
if (rubidium.jobs.length) {
3836
return makeTimeout(rubidium);
3937
}
@@ -49,9 +47,8 @@ function makeNext(rubidium) {
4947
/**
5048
* Sorting function for jobs.
5149
*/
52-
function sortJobs(a, b) {
53-
'use strict';
5450

51+
function sortJobs(a, b) {
5552
return a.time - b.time;
5653
}
5754

@@ -63,8 +60,6 @@ function sortJobs(a, b) {
6360
*/
6461

6562
function Rubidium(jobs) {
66-
'use strict';
67-
6863
var rubidium = this;
6964

7065
if (!(rubidium instanceof Rubidium)) {
@@ -98,8 +93,6 @@ util.inherits(Rubidium, EventEmitter);
9893
*/
9994

10095
Rubidium.prototype.add = function (time, message) {
101-
'use strict';
102-
10396
var job = new Job(time, message);
10497

10598
this.emit('addJob', job);
@@ -139,8 +132,6 @@ Rubidium.prototype.add = function (time, message) {
139132
*/
140133

141134
function getIndex(rubidium, hash) {
142-
'use strict';
143-
144135
var jobs = rubidium.jobs;
145136

146137
for (var i = 0, len = jobs.length; i < len; i++) {
@@ -161,8 +152,6 @@ function getIndex(rubidium, hash) {
161152
*/
162153

163154
Rubidium.prototype.find = function (hash) {
164-
'use strict';
165-
166155
var index = getIndex(this, hash);
167156

168157
if (index !== -1) {
@@ -179,27 +168,25 @@ Rubidium.prototype.find = function (hash) {
179168
*/
180169

181170
Rubidium.prototype.remove = function (hash) {
182-
'use strict';
183-
184171
var index = getIndex(this, hash);
185172
var job = this.jobs[index];
186173

187174
this.emit('removeJob', job);
188175

189176
if (!job) {
190-
return false;
177+
return;
191178
}
192179

193180
if (job === this.jobs[0]) {
194181
this.jobs.shift();
195182
makeNext(this);
196183

197-
return true;
184+
return job;
198185
}
199186

200187
this.jobs.splice(index, 1);
201188

202-
return true;
189+
return job;
203190
};
204191

205192
module.exports = Rubidium;

package.json

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,29 @@
44
"description": "A small unique job scheduler.",
55
"main": "index.js",
66
"scripts": {
7-
"test": "jshint *.js ./lib/*.js ./test/*.js && jscs *.js ./lib/*.js ./test/*.js && nodeunit test",
8-
"coveralls": "istanbul cover nodeunit test && cat ./coverage/lcov.info | coveralls --verbose"
7+
"test": "jshint *.js ./lib/*.js ./test/*.js && jscs *.js ./lib/*.js ./test/*.js && mocha test",
8+
"coveralls": "istanbul cover _mocha --report lcovonly && cat ./coverage/lcov.info | coveralls --verbose"
99
},
1010
"repository": {
1111
"type": "git",
1212
"url": "https://github.com/qubyte/rubidium"
1313
},
1414
"dependencies": {
15-
"json-stable-stringify": "0.1.1"
15+
"json-stable-stringify": "1.0.0"
1616
},
1717
"devDependencies": {
18-
"nodeunit": "0.8.6",
19-
"jshint": "2.4.4",
20-
"jscs": "1.3.0",
21-
"coveralls": "2.8.0",
22-
"istanbul": "0.2.6"
18+
"coveralls": "2.11.2",
19+
"istanbul": "0.3.5",
20+
"jscs": "1.10.0",
21+
"jshint": "2.6.0",
22+
"mocha": "2.1.0",
23+
"mocha-lcov-reporter": "0.0.1",
24+
"sinon": "1.12.2"
2325
},
26+
"files": [
27+
"index.js",
28+
"lib"
29+
],
2430
"keywords": [
2531
"cron",
2632
"schedule",
@@ -55,6 +61,7 @@
5561
"maxlen": 100,
5662
"smarttabs": true,
5763
"node": true,
64+
"mocha": true,
5865
"browser": true,
5966
"esnext": true
6067
},
@@ -98,40 +105,12 @@
98105
"disallowQuotedKeysInObjects": true,
99106
"disallowSpaceAfterObjectKeys": true,
100107
"requireCommaBeforeLineBreak": true,
101-
"disallowLeftStickedOperators": [
102-
"?",
103-
"+",
104-
"-",
105-
"/",
106-
"*",
107-
"=",
108-
"==",
109-
"===",
110-
"!=",
111-
"!==",
112-
">",
113-
">=",
114-
"<",
115-
"<="
116-
],
117-
"disallowRightStickedOperators": [
118-
"?",
119-
"+",
120-
"/",
121-
"*",
122-
"=",
123-
"==",
124-
"===",
125-
"!=",
126-
"!==",
127-
">",
128-
">=",
129-
"<",
130-
"<="
131-
],
132-
"requireLeftStickedOperators": [
108+
"requireSpaceBeforeBinaryOperators": true,
109+
"disallowSpaceBeforeBinaryOperators": [
133110
","
134111
],
112+
"disallowSpaceBeforePostfixUnaryOperators": true,
113+
"requireSpacesInConditionalExpression": true,
135114
"disallowSpaceAfterPrefixUnaryOperators": [
136115
"++",
137116
"--",

0 commit comments

Comments
 (0)