Skip to main content

Class: QueueWorker

Defined in: libs/sdk/src/worker.ts:124

QueueWorker gives a reliable polling loop over the Rinda HTTP API: long-poll, hand each message to a handler, delete on success, and leave it for redelivery on failure.

Reports lifecycle events back to Rinda for introspection (fire-and-forget).

The polling machinery is currently supplied by sqs-consumer, driven through a shim that turns its client calls into Rinda API requests — no cloud credentials are involved. That the dependency exists at all is visible to anyone who installs this package, which is a reason to replace it with a plain loop rather than a detail to paper over in a comment.

Example​

const worker = rinda.queue('orders').createWorker({
handler: async (msg) => {
await processOrder(msg.body);
return msg; // acknowledge
},
batchSize: 5,
visibilityTimeout: 60,
});
worker.start();
worker.on('error', (err) => console.error(err));
await worker.stop();

Constructors​

new QueueWorker()​

new QueueWorker(http, queueId, options): QueueWorker

Defined in: libs/sdk/src/worker.ts:144

Parameters​

http​

HttpClient

queueId​

string

options​

WorkerOptions

Returns​

QueueWorker

Accessors​

isRunning​

Get Signature​

get isRunning(): boolean

Defined in: libs/sdk/src/worker.ts:198

Whether the worker is currently running.

Returns​

boolean

Methods​

on()​

on(event, listener): this

Defined in: libs/sdk/src/worker.ts:203

Register an event listener.

Parameters​

event​

WorkerEvent

listener​

(...args) => void

Returns​

this


start()​

start(): void

Defined in: libs/sdk/src/worker.ts:164

Start the worker polling loop.

Returns​

void


stop()​

stop(): Promise<void>

Defined in: libs/sdk/src/worker.ts:180

Stop polling and wait for the in-flight batch to finish.

Returns a promise so callers can await a clean shutdown, but stays fire-and-forget compatible for existing callers that ignore it. After shutdownWaitMs it stops waiting and emits stopped regardless — a wedged handler must not hold the process open forever.

Returns​

Promise<void>