lib-task-scheduler
Advanced tools
Comparing version 1.0.13 to 1.0.15
@@ -25,4 +25,7 @@ /// <reference types="node" /> | ||
*/ | ||
name: string; | ||
name?: string; | ||
} | ||
export interface MomentDuration { | ||
asMilliseconds(): number; | ||
} | ||
export interface Guard { | ||
@@ -53,3 +56,3 @@ getExclusive(name: string, ttlSeconds: number): Promise<boolean>; | ||
*/ | ||
schedule(task: Task, config: TaskConfig): void; | ||
schedule(task: Task, configArg: MomentDuration | number | TaskConfig): void; | ||
/** | ||
@@ -56,0 +59,0 @@ * Begin a graceful shutdown of the scheduler. This will wait for all *actively* running |
@@ -39,6 +39,35 @@ "use strict"; | ||
*/ | ||
schedule(task, config) { | ||
schedule(task, configArg) { | ||
if (this.isShutdown) { | ||
throw new Error('Scheduler has been shutdown.'); | ||
} | ||
let config; | ||
if (!configArg) { | ||
throw new Error('Schedule config (second argument) is required.'); | ||
} | ||
else if (_.isFunction(configArg.asMilliseconds)) { | ||
config = { | ||
intervalMs: configArg.asMilliseconds(), | ||
}; | ||
} | ||
else if (_.isInteger(configArg)) { | ||
config = { | ||
intervalMs: configArg, | ||
}; | ||
} | ||
else if (_.isInteger(_.get(configArg, 'intervalMs'))) { | ||
config = configArg; | ||
} | ||
else { | ||
throw new Error('Schedule config (second argument) must be an duration, number, or object with intervalMs.'); | ||
} | ||
if (!config.name && _.has(task, 'name')) { | ||
config.name = task.name; | ||
} | ||
else if (!config.name && _.has(task, 'constructor.name')) { | ||
config.name = task.constructor.name; | ||
} | ||
else if (!config.name) { | ||
throw new Error('Task must be configured with a name (either through its TaskConfig, a name property, or having a named constructor)'); | ||
} | ||
if (config.intervalMs <= 0) { | ||
@@ -45,0 +74,0 @@ throw new Error('Task interval must be greater than zero.'); |
{ | ||
"name": "lib-task-scheduler", | ||
"version": "1.0.13", | ||
"version": "1.0.15", | ||
"description": "A lightweight, modular task scheduler.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/convoyinc/lib-task-scheduler", |
Sorry, the diff of this file is not supported yet
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
102731
1483