Skip to content

feat: defer job function

Duncan Bennett requested to merge 827-deferred-jobs into main

Adds "services/jobs.js" and "registerJob" which:

  • Subscribes a handler function to a named list
  • Creates and then returns a wrapper function which publishes handler params to the named list, along with the number of seconds to wait before invoking the job handler.

Eg:

const deferUniqueJob = await registerJob('unique-name', uniqueFn)
await deferUniqueJob(30, {someParam: 'has some value})
await deferUniqueJob(
  {days: 1, hours: 1, minutes: 1, seconds: 1},
  {someParam: 'has some other value'}
)
await deferUniqueJob(
  {minutes: 0.75}, {someParam: 'has yet another value'}
)

Adds tests for "registerJob".

Related to https://gitlab.coko.foundation/ketida/ketida/-/issues/827

Edited by Duncan Bennett

Merge request reports