5.0.1 • Published 4 years ago

@splytech-io/scheduler v5.0.1

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
4 years ago

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().

5.0.1

4 years ago

6.0.0-beta.0

4 years ago

5.0.0

4 years ago

4.0.0

4 years ago

3.1.5

5 years ago

3.1.4

5 years ago

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.5.0

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago