UNPKG

ha-job-scheduler

Version:

Highly available cron job scheduler using Redis

47 lines (46 loc) 1.89 kB
import { RunDelayed, Delayed, Recurring, Events } from './types'; import { RedisOptions } from 'ioredis'; import EventEmitter from 'eventemitter3'; /** * Uses Redis to scheduling recurring jobs or delayed jobs. */ export declare const jobScheduler: (opts?: RedisOptions) => { /** * Schedule a recurring job. `runFn` will be called for every invocation of the rule. * * Set `persistScheduledMs` to a value greater than the frequency of the cron * rule to guarantee that the last missed job will be run. This is useful for * infrequent jobs that cannot be missed. For example, if you have a job that runs * at 6am daily, you might want to set `persistScheduledMs` to `ms('25h')` so that * a missed run will be attempted up to one hour past the scheduled invocation. * * The `id` should be unique for the rule/runFn pair. * * Guarantees at most one delivery. */ scheduleRecurring: Recurring; /** * Schedule data to be delivered at a later date. Duplicate payloads * will be ignored. `scheduleFor` accepts a number of milliseconds * in the future or a date. Use in conjunction with `runDelayed`. * * Returns a boolean indicating if the item was successfully scheduled. */ scheduleDelayed: Delayed; /** * Check for delayed items according to the recurrence rule. Default * interval is every minute. Calls `runFn` for the batch of items where * the delayed timestamp is <= now. The default number of items to * retrieve at one time is 100. * * The `id` parameter should match the `id` passed to `scheduleDelayed`. * * Guarantees at least one delivery. */ runDelayed: RunDelayed; /** * Call stop on all schedulers and close the Redis connection. */ stop: () => Promise<void>; emitter: EventEmitter<Events, any>; };