handle method

  1. @override
Future<void> handle(
  1. QueueJobContext context,
  2. Next next
)
override

Handle the job context Call next() to continue to the next middleware or job execution

Implementation

@override
Future<void> handle(QueueJobContext context, Next next) async {
  final jobId = context.metadata['job_id'] as String?;
  if (jobId == null) {
    await next();
    return;
  }

  final now = DateTime.now();
  final lastProcessed = _processedJobs[jobId];

  if (lastProcessed != null && now.difference(lastProcessed) < window) {
    // Skip duplicate job
    return;
  }

  _processedJobs[jobId] = now;

  // Clean old entries
  _processedJobs.removeWhere(
    (key, value) => now.difference(value) > window,
  );

  await next();
}