execute method

Future<void> execute(
  1. QueueJobContext context
)

Execute the pipeline

Implementation

Future<void> execute(QueueJobContext context) async {
  if (_middleware.isEmpty) {
    // No middleware, just execute the job
    await _executeJob(context);
    return;
  }

  // Build the middleware chain
  int index = 0;

  Future<void> next() async {
    if (index >= _middleware.length) {
      // End of middleware chain, execute the job
      await _executeJob(context);
      return;
    }

    final middleware = _middleware[index++];
    await middleware.handle(context, next);
  }

  await next();
}