@splytech-io/scheduler v5.0.1
Scheduler
Features
- manual job reschedule
- custom reschedule time offset
- log errors to the db
- worker pool
- custom job polling interval
- multiple runners
- custom mongodb collection
- track total time spent on a job
- minimal db index size
API
new Scheduler(options: SchedulerOptions)
Method
registerRunner(runnerConstructor: RunnerConstructor<Params, Context>, options: RunnerDaemonOptions)
Regsiters a runner which will process specific jobs. RunnerConstructor
must be a class which extends Runner<Params, Context>
abstract class and
implements at least run()
method. See examples directory.
interface RunnerDaemonOptions {
limit: number; // pool size - maximum number of job to process in parallel
pollInterval: number; // the interval in which db will be queried for new records
}
createJob\<Params, Context>(runnerConstructor: Runner\<Params, Context>, params: Params): Promise\
Creates a job for a specific runner. Throws if runner is not registered.
start(): Promise;
Creates database indexes and starts runner daemon.
stop(): Promise;
Stops runner daemon and ensures all running jobs complete before resolving returned promise.
Runner\<RunnerParams, Context = undefined>
Methods
done(): Promise\
Deletes the job from the database.
reschedule(timeOffsetMS: number): Promise\
Reschedules the job.
Hooks
Hooks are methods of the runner which are called on specific runner lifecycle events.
run()
run()
method is executed when daemon finds a job to process. The job and it's params can be retrieved by accessing this.job
inside a run()
function.
onSuccess(result: any)
methods gets called when run()
finishes without an error. Result is the returned value from run()
method.
onError(e: Error)
method is executed when run()
throws.
onFinish()
this hook is executed in both cases: is run()
succeeds or fails and after calling onSuccess()
or onError()
.
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago