work method
Future<void>
work({
- List<
String> queues = const ['default'], - int concurrency = 1,
- int maxJobsPerSecond = 0,
- Duration pollInterval = const Duration(milliseconds: 500),
- JobEventCallback? onProcess,
- JobEventCallback? onComplete,
- JobEventCallback? onRetry,
- JobEventCallback? onFail,
- JobEventCallback? onTimeout,
Starts a background worker to process jobs.
queues defines which queues to listen to.
concurrency controls how many jobs run in parallel.
maxJobsPerSecond limits throughput (0 = unlimited).
pollInterval controls how often the worker polls for new jobs.
Implementation
Future<void> work({
List<String> queues = const ['default'],
int concurrency = 1,
int maxJobsPerSecond = 0,
Duration pollInterval = const Duration(milliseconds: 500),
JobEventCallback? onProcess,
JobEventCallback? onComplete,
JobEventCallback? onRetry,
JobEventCallback? onFail,
JobEventCallback? onTimeout,
}) async {
await _worker?.stop();
_worker = Worker(
driver: driver,
queues: queues,
concurrency: concurrency,
maxJobsPerSecond: maxJobsPerSecond,
pollInterval: pollInterval,
metrics: metrics,
)
..onProcess = onProcess
..onComplete = onComplete
..onRetry = onRetry
..onFail = onFail
..onTimeout = onTimeout;
// Start in the background — don't await the future (it completes on stop)
// ignore: unawaited_future
_worker?.start();
}