Skip to content

API

feathers-tasks is assembled from composable building blocks — there is no single app.configure() plugin. Each function below is imported from @kalisio/feathers-tasks.

createQueue (name, redisOptions)

Creates a BullMQ Queue connected to Redis and returns it.

ParameterTypeRequiredDescription
namestringyesQueue name — must match the worker and queue-events.
redisOptionsobjectyesRedis connection options passed to BullMQ ({ host, port, password, ... }).

createWorker (queueName, redisOptions, handlers?, concurrency?)

Creates a BullMQ Worker that dispatches each job to the handler matching its type, and returns it.

ParameterTypeRequiredDescription
queueNamestringyesQueue to consume.
redisOptionsobjectyesRedis connection options.
handlersobjectnoMap of taskType → async (job) => any. Selected from job.name. Default: {}.
concurrencynumbernoJobs processed in parallel by this worker. Default: 1.

If no handler matches a job's type, the worker resolves it as a no-op (it does not throw).

setupQueueEvents (queueName, redisOptions, app, persistenceService)

Subscribes to the queue lifecycle events (active, progress, completed, failed) and patches the persistence record accordingly. Returns the QueueEvents instance.

ParameterTypeRequiredDescription
queueNamestringyesQueue to observe.
redisOptionsobjectyesRedis connection options.
appFeathers appyesUsed to resolve the persistence service.
persistenceServicestringyesName of the Feathers service holding task history.

setupDashboard (app, queue, basePath)

Mounts the Bull Board UI as Express middleware on the underlying app.

ParameterTypeRequiredDescription
appFeathers appyesMust be an Express-powered Feathers app (@feathersjs/express).
queueQueueyesThe BullMQ queue to expose.
basePathstringyesURL path where the dashboard is served, e.g. /admin/tasks.

new TaskService ({ queue, persistenceService })

Feathers service constructor.

OptionTypeRequiredDescription
queueQueueyesA BullMQ queue (from createQueue).
persistenceServicestringyesName of the Feathers service used to store task history.

Register it with app.use('tasks', new TaskService({ ... })). Its methods follow.

TaskService

create (data, params)

Submits a new task to the BullMQ queue and creates a record in the persistence service.

PropertyTypeRequiredDescription
data.typestringyesJob type — matched against a key in handlers.
data.payloadobjectnoArbitrary data forwarded to the handler as job.data.
data.optionsobjectnoBullMQ JobsOptions (delay, attempts, priority, etc.).

Returns the persisted task record:

FieldDescription
idBullMQ job id.
typeJob type.
payloadData passed to the handler.
status'waiting' at creation time.
createdAtISO timestamp.

find (params)

Delegates to the persistence service. Accepts the same params.query as the underlying adapter.

Returns a list (or paginated result) of task records.

get (id, params)

Retrieves a single task record from the persistence service by BullMQ job id.

ParameterDescription
idBullMQ job id (string).

Throws NotFound if no record matches.

patch (id, data, params)

Updates fields on a task record in the persistence service. Primarily used internally by the QueueEvents listener to reflect status changes.

ParameterDescription
idBullMQ job id.
dataFields to merge into the record (e.g. { status, completedAt, result }).

remove (id, params)

Cancels the BullMQ job (if still pending) and removes the record from the persistence service.

ParameterDescription
idBullMQ job id.

Throws NotFound if no persistence record matches. Does not throw if the job is no longer in the queue (already completed/failed).