New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dronos

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dronos - npm Package Compare versions

Comparing version 0.0.14 to 0.1.1

329

lib/dronos.js

@@ -59,10 +59,21 @@ "use strict";

/**
* @callback Dronos~var var done
* @param {?Error} err - If an error occurred, this is the Error object.
* @param {?*} data - If no error occurred this is optionally data, or null if no data expected.
* @typedef {object} Dronos~scheduleParams
* @property {string|number|null|undefined|array|Dronos~scheduleParams} * - Any arbitrary set of key/value properties which must only contain serializable data types
*/
/**
* @typedef {object} Dronos~schedule
* @param {object} schedule
* @param {boolean} [schedule.enabled=TRUE] - Whether or not the schedule is active (will actually fire and iterate a recurrence).
* @param {string} schedule.owner - The id of the owner of the schedule. The combination of owner and name must be unique.
* @param{string} schedule.name - The name of the schedule. The combination of owner and name must be unique.
* @param {string} schedule.recurrence - A cron compatible specification for the recurrence pattern http://en.wikipedia.org/wiki/Cron#Examples
* @param {Date} [schedule.start=1969-12-31 23:59:59Z] - Run this schedule only on dates after the this one.
* @param {Date} [schedule.end=] - Run this schedule only on dates before the this one.
* @param {Dronos~scheduleParams} [schedule.params={}] - Arbitrary parameters to pass to the handler function when running instances.
*/
/**
* @callback Dronos~handler
* @param {?object.<string,*>} params - Arbitrary parameters that were set when with the schedule.
* @param {Dronos~scheduleParams} params - Arbitrary parameters that were set with the schedule.
* @param {done} done - A function to call when the handler is done processing the event.

@@ -72,2 +83,19 @@ */

/**
* @callback Dronos~basic
* @param {Error|null|undefined} [err] - If there was an error, this will contain an error object, any other value indicates no error
*/
/**
* @callback Dronos~scheduleEcho
* @param {Error|null|undefined} [err] - If there was an error, this will contain an error object, any other value indicates no error
* @param {Dronos~schedule} [schedule] - If there was no error, this will contain a valid schedule definition object.
*/
/**
* @callback Dronos~ack
* @param {Error|null|undefined} [err] - If there was an error, this will contain an error object, any other value indicates no error
* @param {boolean} [ack] - If the command was possible and completed, TRUE, otherwise FALSE
*/
/**
* Set Schedule

@@ -77,10 +105,4 @@ *

*
* @param {object} schedule
* {string} schedule.owner - The id of the owner of the schedule. The combination of owner and name must be unique.
* {string} schedule.name - The name of the schedule. The combination of owner and name must be unique.
* {string} schedule.recurrence - A cron compatible specification for the recurrence pattern http://en.wikipedia.org/wiki/Cron#Examples
* {Date} schedule.start - Run this schedule only on dates after the this one.
* {Date} schedule.end - Run this schedule only on dates before the this one.
* {?object.<string,*>} schedule.params - Arbitrary parameters to pass to the handler function when running instances.
* @param {done} done - Called after the schedule entry has been upserted or denied.
* @param {schedule} schedule - The schedule pattern to set.
* @param {Dronos~scheduleEcho} done - Called after the schedule entry has been upserted or denied.
*

@@ -90,5 +112,3 @@ */

if ( typeof done !== 'function' ) {
throw new Error( 'done should be a function' );
}
done = nonoop( done );

@@ -114,12 +134,25 @@ var _done = function( err, schedule ) {

schedule._nextRun = nextRun.toDate();
schedule._lastUpdate = new Date();
/**
* @type {object}
* @augments Dronos~schedule
* @param {date} _nextRun - The next time the schedule should event
* @param {date} _lastUpdate - The last time the schedule record was modified
*/
var scheduleEntry = schedule;
scheduleEntry._nextRun = nextRun.toDate();
scheduleEntry._lastUpdate = new Date();
// default this value
if ( !scheduleEntry.hasOwnProperty( 'enabled' ) ) {
scheduleEntry.enabled = true;
}
this._models.Dronos.findOneAndUpdate(
{
owner: schedule.owner,
name: schedule.name
owner: scheduleEntry.owner,
name: scheduleEntry.name
},
{
$set: schedule,
$set: scheduleEntry,
$inc: {

@@ -158,3 +191,3 @@ _version: 1

* {string} schedule.name - The name of the schedule. The combination of owner and name must be unique.
* @param {done} done - Called after the schedule entry has been removed. If removal command was a success, the data field will be true if an existing entry was deleted, or false if no entry matched the owner/name combination.
* @param {Dronos~scheduleEcho} done - Callback to receive error or the schedule definition.
*

@@ -164,2 +197,4 @@ */

done = nonoop( done );
if ( !validateScheduleBasicFields( schedule, done ) ) {

@@ -190,3 +225,3 @@ return;

* {string} schedule.name - The name of the schedule. The combination of owner and name must be unique.
* @param {done} done - Called after the schedule entry has been removed. If removal command was a success, the data field will be true if an existing entry was deleted, or false if no entry matched the owner/name combination.
* @param {Dronos~ack} done - Called after the schedule entry has been removed. If there was a matching schedule to delete, and no error occurred, TRUE, otherwise FALSE.
*

@@ -196,2 +231,4 @@ */

done = noop( done );
if ( !validateScheduleBasicFields( schedule, done ) ) {

@@ -215,2 +252,98 @@ return;

/**
* Enable Schedule
*
* Enables a schedule to be evented.
*
* @param {object} schedule
* {string} schedule.owner - The id of the owner of the schedule.
* {string} schedule.name - The name of the schedule.
* @param {Dronos~ack} done - Called after the schedule entry has been enabled. Will have data TRUE if a schedule was found and enabled, FALSE otherwise
*
*/
Dronos.prototype.enable = function( schedule, done ) {
done = noop( done );
if ( !validateScheduleBasicFields( schedule, done ) ) {
return;
}
this._models.Dronos.findOneAndUpdate(
{
owner: schedule.owner,
name: schedule.name
},
{
$set: {
enabled: true,
_lastUpdate: new Date()
},
$inc: {
_version: 1
}
},
{
upsert: false,
new: true
},
function( err, schedule ) {
if ( err ) {
done( err );
return;
}
done( null, !!(schedule && schedule.enabled) );
}
);
};
/**
* Enable Schedule
*
* Enables a schedule to be evented.
*
* @param {object} schedule
* {string} schedule.owner - The id of the owner of the schedule.
* {string} schedule.name - The name of the schedule.
* @param {Dronos~ack} done - Called after the schedule entry has been disabled. Will have data TRUE if a schedule was found and disabled, FALSE otherwise
*
*/
Dronos.prototype.disable = function( schedule, done ) {
done = noop( done );
if ( !validateScheduleBasicFields( schedule, done ) ) {
return;
}
this._models.Dronos.findOneAndUpdate(
{
owner: schedule.owner,
name: schedule.name
},
{
$set: {
enabled: false,
_lastUpdate: new Date()
},
$inc: {
_version: 1
}
},
{
upsert: false,
new: true
},
function( err, schedule ) {
if ( err ) {
done( err );
return;
}
done( null, !!(schedule && !schedule.enabled) );
}
);
};
/**
* Listen to all Schedules

@@ -221,4 +354,4 @@ *

*
* @param {handler} run - The handler to run when the schedule runs an instance.
* @return {boolean} TRUE for success, FALSE for failure
* @param {Dronos~handler} run - The handler to run when the schedule runs an instance.
* @return {boolean} TRUE for success registration, FALSE for failure.
*/

@@ -242,10 +375,8 @@ Dronos.prototype.listenAll = function( run ) {

* {string} schedule.name - The name of the schedule. The combination of owner and name must be unique.
* @param {handler} run - The handler to run when the schedule runs an instance.
* @param {done} done
* @param {Dronos~handler} run - The handler to run when the schedule runs an instance.
* @param {Dronos~basic} done - The call back fired once after listen registration complete
*/
Dronos.prototype.listen = function( schedule, run, done ) {
if ( typeof done !== 'function' ) {
throw new Error( 'run field must be a function' );
}
done = noop( done );

@@ -285,2 +416,7 @@ if ( !validateScheduleBasicFields( schedule, done ) ) {

/**
* Start schedule execution runner
*
* When a Dronos instance is started, it will begin firing events for all active, registered schedules as often as once per minute.
*/
Dronos.prototype.start = function() {

@@ -296,2 +432,3 @@

var go = function() {
// if no longer running, nothing to do

@@ -302,4 +439,21 @@ if ( self._running === false ) {

self._runReadySchedules( function() {
async.series( [
function( done ) {
// upgrade old schedule entries to 0.1.x schema
self._models.Dronos.update(
{
enabled: { $exists: false }
},
{
$set: { enabled: true }
},
done
);
},
function( done ) {
self._runReadySchedules( done );
}
], function() {
// if no longer running, nothing to do

@@ -330,2 +484,3 @@ if ( self._running === false ) {

} );
};

@@ -337,2 +492,7 @@

/**
* Stop schedule execution runner
*
* Stops a Dronos instance from firing dronos events.
*/
Dronos.prototype.stop = function() {

@@ -359,2 +519,3 @@

self._models.Dronos.find( {
enabled: true,
_nextRun: { $lt: moment().toISOString() }

@@ -490,18 +651,18 @@ },

if ( ![ 'owner', 'name' ].every( function( field ) {
var result = schedule.hasOwnProperty( field ) &&
typeof schedule[ field ] === 'string' &&
schedule[ field ].length > 0;
if ( !result ) {
done( field + ' is a required string parameter' );
}
return result;
} ) ) {
return false;
}
return [ 'owner', 'name' ].every( function( field ) {
var result = schedule.hasOwnProperty( field ) &&
typeof schedule[ field ] === 'string' &&
schedule[ field ].length > 0;
if ( !result ) {
done( field + ' is a required string parameter' );
}
return result;
} );
return true;
}
function validateScheduleBasicFields( schedule, done ) {
done = nonoop( done );
return _validateScheduleBasicFields( schedule, function( err ) {

@@ -518,2 +679,4 @@ if ( err ) {

done = nonoop( done );
if ( !_validateScheduleBasicFields( schedule, done ) ) {

@@ -523,2 +686,16 @@ return false;

// optional boolean fields
if ( ![ 'enabled' ].every( function( field ) {
if ( schedule.hasOwnProperty( field ) ) {
return typeof schedule[ field ] === 'boolean';
}
return true;
} ) ) {
return false;
}
// required, non-empty strings
if ( ![ 'recurrence' ].every( function( field ) {

@@ -536,30 +713,28 @@ var result = schedule.hasOwnProperty( field ) &&

if ( ![ 'start', 'end' ].every( function( field ) {
// optional dates
return [ 'start', 'end' ].every( function( field ) {
if ( !schedule.hasOwnProperty( field ) ) {
return true;
}
if ( !schedule.hasOwnProperty( field ) ) {
return true;
}
if ( schedule[ field ] instanceof moment ) {
return true;
}
if ( schedule[ field ] instanceof moment ) {
return true;
}
if ( typeof schedule[ field ] === 'string' && schedule[ field ].match( /^[0-9]{4}-[0-9]{2}-[0-9]{2}[ T][0-9]{2}:[0-9]{2}:[0-9]{2}\.?[0-9]{0,3}Z/ ) ) {
schedule[ field ] = moment( schedule[ field ] );
return true;
}
if ( typeof schedule[ field ] === 'string' && schedule[ field ].match( /^[0-9]{4}-[0-9]{2}-[0-9]{2}[ T][0-9]{2}:[0-9]{2}:[0-9]{2}\.?[0-9]{0,3}Z/ ) ) {
schedule[ field ] = moment( schedule[ field ] );
return true;
}
if ( typeof schedule[ field ] === 'object' && typeof schedule[ field ].toISOString === 'function' ) {
schedule[ field ] = moment( schedule[ field ].toISOString() );
return true;
}
if ( typeof schedule[ field ] === 'object' && typeof schedule[ field ].toISOString === 'function' ) {
schedule[ field ] = moment( schedule[ field ].toISOString() );
return true;
}
done( field + ' is not a valid time string, Date instance or moment instance' );
return false;
} ) ) {
done( field + ' is not a valid time string, Date instance or moment instance' );
return false;
}
return true;
} );
}

@@ -574,10 +749,14 @@

var now = moment();
// If the schedule has a start time, ensure the next run time is after that start time
if ( schedule.hasOwnProperty( 'start' ) && moment( schedule.start ).isAfter( now ) ) {
args.push( schedule.start );
} else {
} else { // The later module has a bug where it will calculate next to be now if there are < 1 second on the current time stamp
args.push( now.add( 1, 'second' ).toISOString() );
}
// gets the next run time of the schedule and clamps milli/seconds to zero
var nextRun = moment( s.next.apply( s, args ).toISOString() ).millisecond( 0 ).seconds( 0 );
// if schedule has an end time, and next time is beyond that point, cancel the next run
if ( schedule.hasOwnProperty( 'end' ) && moment( schedule.end ).isBefore( nextRun ) ) {

@@ -589,1 +768,23 @@ return null;

}
function noop( cb ) {
if ( typeof cb === 'function' ) {
return cb;
}
return function() {
// NO-OP
};
}
function nonoop( cb ) {
if ( typeof cb === 'function' ) {
return cb;
}
throw new Error( 'callback must be a function' );
}

3

lib/models/dronos.js

@@ -32,2 +32,3 @@ "use strict";

name: { type: String, required: true }, // the name of this schedule,
enabled: { type: Boolean, required: false, default: true }, // Is the schedule enabled,
recurrence: { type: String, required: true }, // the cron compatible specification for the recurrence pattern http://en.wikipedia.org/wiki/Cron#Examples

@@ -52,3 +53,3 @@ start: { type: Date, default: null }, // repeat the schedule after the specified time

DronosSchema.index( { owner: 1, name: 1, _lastUpdate: -1 } );
DronosSchema.index( { _nextRun: 1, _lastRun: 1 } );
DronosSchema.index( { enabled: 1, _nextRun: 1, _lastRun: 1 } );

@@ -55,0 +56,0 @@ var modelName = 'dronos';

{
"name": "dronos",
"description": "Dronos is a distributed scheduling system (with patterns similar to Linux's cron system), using MongoDB to coordinate running tasks (drons) across multiple nodes.",
"version": "0.0.14",
"version": "0.1.1",
"author": "Anthony Hildoer <anthony@bluerival.com>",

@@ -6,0 +6,0 @@ "repository": {

@@ -18,4 +18,4 @@ "use strict";

dronos = new Dronos();
} );
}, Error );
}, Error );
} );

@@ -25,4 +25,4 @@ it( 'should NOT instantiate', function() {

dronos = new Dronos( {
mongodb: null
} );
mongodb: null
} );
}, Error );

@@ -34,4 +34,4 @@ } );

dronos = new Dronos( {
mongodb: ''
} );
mongodb: ''
} );
}, Error );

@@ -43,4 +43,4 @@ } );

dronos = new Dronos( {
mongodb: undefined
} );
mongodb: undefined
} );
}, Error );

@@ -51,5 +51,5 @@ } );

dronos = new Dronos( {
prefix: '_testing',
mongodb: 'mongodb://localhost/testing'
} );
prefix: '_testing',
mongodb: 'mongodb://localhost/testing'
} );
done();

@@ -65,10 +65,10 @@ } );

dronos = new Dronos( {
prefix: '_testing',
mongodb: 'mongodb://localhost/testing'
} );
prefix: '_testing',
mongodb: 'mongodb://localhost/testing'
} );
dronos.remove( {
owner: '1234',
name: 'a.test.schedule'
}, function( err ) {
owner: '1234',
name: 'a.test.schedule'
}, function( err ) {
done( err );

@@ -83,5 +83,5 @@ } );

dronos.remove( {
owner: '1234',
name: 'a.test.schedule'
}, function( err ) {
owner: '1234',
name: 'a.test.schedule'
}, function( err ) {
done( err );

@@ -100,6 +100,22 @@ } );

} );
}, /done should be a function/ );
}, /callback must be a function/ );
} );
it( 'should NOT set a schedule item with invalid schedule object', function() {
dronos.set( {}, function( err ) {
assert.equal( err.message, 'owner is a required string parameter' );
} );
} );
it( 'should NOT set a schedule item with array as schedule object', function() {
dronos.set( [], function( err ) {
assert.equal( err.message, 'schedule is a required object parameter' );
} );
} );
it( 'should NOT set a schedule item with non-object schedule', function( done ) {

@@ -149,7 +165,7 @@

dronos.set( {
owner: '1234',
name: 'a.test.schedule',
recurrence: '*/15 * * * *',
end: '2013-10-01T00:00:00Z'
}, function( err ) {
owner: '1234',
name: 'a.test.schedule',
recurrence: '*/15 * * * *',
end: '2013-10-01T00:00:00Z'
}, function( err ) {
if ( err ) {

@@ -167,8 +183,8 @@ done();

dronos.set( {
owner: '1234',
name: 'a.test.schedule',
recurrence: '*/15 * * * *',
start: moment().add( 2, 'years' ),
end: moment().add( 2, 'days' )
}, function( err ) {
owner: '1234',
name: 'a.test.schedule',
recurrence: '*/15 * * * *',
start: moment().add( 2, 'years' ),
end: moment().add( 2, 'days' )
}, function( err ) {
if ( err ) {

@@ -325,5 +341,5 @@ done();

var key = JSON.stringify( {
owner: inputSchedule.owner,
name: inputSchedule.name || null
} );
owner: inputSchedule.owner,
name: inputSchedule.name || null
} );

@@ -349,5 +365,5 @@ assert.strictEqual(

dronos.listen( {
owner: '1234',
name: 'a.test.schedule'
}, null, function( err ) {
owner: '1234',
name: 'a.test.schedule'
}, null, function( err ) {

@@ -367,10 +383,8 @@ try {

assert.throws( function() {
dronos.listen( {
owner: '1234',
name: 'a.test.schedule'
}, function() {
// NO-OP
} );
}, /run field must be a function/ );
dronos.listen( {
owner: '1234',
name: 'a.test.schedule'
}, function( err ) {
assert.equal( err.message, 'run field must be a function' );
} );

@@ -395,5 +409,5 @@ } );

dronos.remove( {
owner: '1234',
name: 'a.test.schedule'
}, function( err, removedOne ) {
owner: '1234',
name: 'a.test.schedule'
}, function( err, removedOne ) {

@@ -405,5 +419,5 @@ try {

dronos.remove( {
owner: '1234',
name: 'a.test.schedule'
}, function( err, removedOne ) {
owner: '1234',
name: 'a.test.schedule'
}, function( err, removedOne ) {

@@ -432,5 +446,5 @@ try {

dronos.get( {
owner: '1234',
name: 'a.test.schedule'
}, function( err, schedule ) {
owner: '1234',
name: 'a.test.schedule'
}, function( err, schedule ) {

@@ -451,5 +465,5 @@ try {

dronos.listen( {
owner: '1234',
name: 'a.test.schedule'
}, function() {
owner: '1234',
name: 'a.test.schedule'
}, function() {
// NO-OP

@@ -476,13 +490,13 @@ }, function( err ) {

dronos = new Dronos( {
prefix: '_testing',
mongodb: 'mongodb://localhost/testing'
} );
prefix: '_testing',
mongodb: 'mongodb://localhost/testing'
} );
dronos.remove( {
owner: '1234',
name: 'a.test.schedule'
},
function( err ) {
done( err );
} );
owner: '1234',
name: 'a.test.schedule'
},
function( err ) {
done( err );
} );

@@ -495,8 +509,8 @@ } );

dronos.remove( {
owner: '1234',
name: 'a.test.schedule'
},
function( err ) {
done( err );
} );
owner: '1234',
name: 'a.test.schedule'
},
function( err ) {
done( err );
} );
dronos = null;

@@ -506,3 +520,3 @@

it( 'should fire an event', function( done ) {
it( 'should NOT fire a disabled event', function( done ) {

@@ -512,2 +526,3 @@ var inputSchedule = {

name: 'a.test.schedule',
enabled: false,
recurrence: '* * * * *',

@@ -542,15 +557,229 @@ params: {

var key = JSON.stringify( {
owner: inputSchedule.owner,
name: inputSchedule.name || null
} );
owner: inputSchedule.owner,
name: inputSchedule.name || null
} );
assert.strictEqual( dronos._handlers[ key ], run );
dronos._models.Dronos.update( {}, { $set: { _nextRun: '2011-10-10T00:00:00Z' } }, { multi: true }, function( err, count ) {
dronos._running = true;
dronos._models.Dronos.update( {}, { $set: { _nextRun: '2011-10-10T00:00:00Z' } }, { multi: true }, function() {
dronos._running = true; // simulate call to .start()
dronos._runReadySchedules( function() {
dronos._runReadySchedules( function() {
dronos._running = false;
dronos._running = false; // simulate call to .stop()
try {
assert.strictEqual( runCount, 0 );
done();
} catch ( e ) {
done( e );
}
} );
} );
} );
} catch ( e ) {
done( e );
}
} );
} );
} );
it( 'should NOT fire a disabled event using disable()', function( done ) {
var inputSchedule = {
owner: '1234',
name: 'a.test.schedule',
enabled: true,
recurrence: '* * * * *',
params: {
hi: 'there'
}
};
dronos.set( inputSchedule, function( err ) {
if ( err ) {
done( err );
return;
}
var runCount = 0;
dronos.disable( inputSchedule, function( err ) {
if ( err ) {
done( err );
return;
}
var run = function( schedule, done ) {
runCount++;
done();
};
dronos.listen( inputSchedule, run, function( err ) {
if ( err ) {
done( err );
return;
}
try {
var key = JSON.stringify( {
owner: inputSchedule.owner,
name: inputSchedule.name || null
} );
assert.strictEqual( dronos._handlers[ key ], run );
dronos._models.Dronos.update( {}, { $set: { _nextRun: '2011-10-10T00:00:00Z' } }, { multi: true }, function() {
dronos._running = true; // simulate call to .start()
dronos._runReadySchedules( function() {
dronos._runReadySchedules( function() {
dronos._running = false; // simulate call to .stop()
try {
assert.strictEqual( runCount, 0 );
done();
} catch ( e ) {
done( e );
}
} );
} );
} );
} catch ( e ) {
done( e );
}
} );
} );
} );
} );
it( 'should fire an enabled event using enable()', function( done ) {
var inputSchedule = {
owner: '1234',
name: 'a.test.schedule',
enabled: false,
recurrence: '* * * * *',
params: {
hi: 'there'
}
};
dronos.set( inputSchedule, function( err ) {
if ( err ) {
done( err );
return;
}
var runCount = 0;
dronos.enable( inputSchedule, function( err ) {
if ( err ) {
done( err );
return;
}
var run = function( schedule, done ) {
runCount++;
done();
};
dronos.listen( inputSchedule, run, function( err ) {
if ( err ) {
done( err );
return;
}
try {
var key = JSON.stringify( {
owner: inputSchedule.owner,
name: inputSchedule.name || null
} );
assert.strictEqual( dronos._handlers[ key ], run );
dronos._models.Dronos.update( {}, { $set: { _nextRun: '2011-10-10T00:00:00Z' } }, { multi: true }, function() {
dronos._running = true; // simulate call to .start()
dronos._runReadySchedules( function() {
dronos._runReadySchedules( function() {
dronos._running = false; // simulate call to .stop()
try {
assert.strictEqual( runCount, 1 );
done();
} catch ( e ) {
done( e );
}
} );
} );
} );
} catch ( e ) {
done( e );
}
} );
} );
} );
} );
it( 'should fire an event with default to enabled', function( done ) {
var inputSchedule = {
owner: '1234',
name: 'a.test.schedule',
recurrence: '* * * * *',
params: {
hi: 'there'
}
};
dronos.set( inputSchedule, function( err ) {
if ( err ) {
done( err );
return;
}
var runCount = 0;
var run = function( schedule, done ) {
runCount++;
done();
};
dronos.listen( inputSchedule, run, function( err ) {
if ( err ) {
done( err );
return;
}
try {
var key = JSON.stringify( {
owner: inputSchedule.owner,
name: inputSchedule.name || null
} );
assert.strictEqual( dronos._handlers[ key ], run );
dronos._models.Dronos.update( {}, { $set: { _nextRun: '2011-10-10T00:00:00Z' } }, { multi: true }, function() {
dronos._running = true; // simulate call to .start()
dronos._runReadySchedules( function() {
dronos._runReadySchedules( function() {
dronos._running = false; // simulate call to .stop()
try {
assert.strictEqual( runCount, 1 );

@@ -575,2 +804,69 @@ done();

it( 'should fire an event with explicit enabled', function( done ) {
var inputSchedule = {
owner: '1234',
name: 'a.test.schedule',
enabled: true,
recurrence: '* * * * *',
params: {
hi: 'there'
}
};
dronos.set( inputSchedule, function( err ) {
if ( err ) {
done( err );
return;
}
var runCount = 0;
var run = function( schedule, done ) {
runCount++;
done();
};
dronos.listen( inputSchedule, run, function( err ) {
if ( err ) {
done( err );
return;
}
try {
var key = JSON.stringify( {
owner: inputSchedule.owner,
name: inputSchedule.name || null
} );
assert.strictEqual( dronos._handlers[ key ], run );
dronos._models.Dronos.update( {}, { $set: { _nextRun: '2011-10-10T00:00:00Z' } }, { multi: true }, function() {
dronos._running = true; // simulate call to .start()
dronos._runReadySchedules( function() {
dronos._runReadySchedules( function() {
dronos._running = false; // simulate call to .stop()
try {
assert.strictEqual( runCount, 1 );
done();
} catch ( e ) {
done( e );
}
} );
} );
} );
} catch ( e ) {
done( e );
}
} );
} );
} );
} );

@@ -577,0 +873,0 @@

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