pop method

  1. @override
Future<Job?> pop([
  1. String queue = 'default'
])
override

Pops the next available job from the queue atomically.

Implementations MUST guarantee that no two workers can receive the same job (distributed lock / atomic dequeue). Returns null if the queue is empty or no jobs are available.

Implementation

@override
Future<Job?> pop([String queue = 'default']) async {
  final q = _queue(queue);
  if (q.isEmpty) return null;

  // Find the first available job (respects delayed/retry scheduling)
  for (int i = 0; i < q.length; i++) {
    final job = q.removeFirst();
    if (job.isAvailable) return job;
    // Not yet available, put it back at the end
    q.add(job);
  }

  return null; // All jobs are delayed
}