startWorker method

Future<void> startWorker({
  1. int? maxJobs,
  2. Duration delay = const Duration(seconds: 1),
  3. Duration? timeout,
  4. bool runInBackground = false,
  5. void onError(
    1. dynamic error,
    2. StackTrace stack
    )?,
  6. void onJobStart(
    1. QueueJob job
    )?,
  7. void onJobComplete(
    1. QueueJob job,
    2. dynamic result
    )?,
  8. void onJobError(
    1. QueueJob job,
    2. dynamic error,
    3. StackTrace stack
    )?,
})

Starts a queue worker with the specified configuration.

Implementation

Future<void> startWorker({
  int? maxJobs,
  Duration delay = const Duration(seconds: 1),
  Duration? timeout,
  bool runInBackground = false,
  void Function(dynamic error, StackTrace stack)? onError,
  void Function(QueueJob job)? onJobStart,
  void Function(QueueJob job, dynamic result)? onJobComplete,
  void Function(QueueJob job, dynamic error, StackTrace stack)? onJobError,
}) async {
  final config = QueueWorkerConfig(
    maxJobs: maxJobs,
    delay: delay,
    timeout: timeout,
    runInBackground: runInBackground,
    onError: onError,
    onJobStart: onJobStart,
    onJobComplete: onJobComplete,
    onJobError: onJobError,
  );

  final worker = QueueWorker(_defaultDriver!, config);
  await worker.start();
}