Worker class

Consumes messages from the app's broker and executes the matching tasks, handling retries, backoff, and result storage. Analogous to the Celery worker process — except concurrency here is cooperative async within a single isolate (great for IO-bound tasks); scale CPU-bound work by launching additional worker processes.

Constructors

Worker(GisilaQueue app, {required List<String> queues, int concurrency = 1, Duration reserveTimeout = const Duration(seconds: 5), String? id, Duration heartbeatInterval = const Duration(seconds: 10)})

Properties

app GisilaQueue
final
concurrency int
Number of messages processed concurrently within this process.
final
hashCode int
The hash code for this object.
no setterinherited
heartbeatInterval Duration
How often a QueueEventType.workerHeartbeat is emitted while running.
final
id String
Stable identity reported on every worker QueueEvent, so a dashboard can group a process's activity and detect when it goes offline.
final
isRunning bool
Whether the worker is currently consuming.
no setter
onFailure TaskObserver?
Invoked after each terminal failure.
getter/setter pair
onRetry TaskObserver?
Invoked whenever a task is re-enqueued for retry.
getter/setter pair
onSuccess TaskObserver?
Invoked after each successful task.
getter/setter pair
queues List<String>
Queues consumed in priority order — earlier queues are drained first.
final
reserveTimeout Duration
How long each reserve call blocks waiting for work before looping.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run() Future<void>
Starts the consumer loops and resolves only after stop is called (or an unrecoverable error). Run this as the body of a worker process.
stop() Future<void>
Signals every consumer loop to stop after its current task and waits for them to drain.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited