Webador / SlmQueue

Laminas / Mezzio module that integrates with various queue management systems.
Other
137 stars 56 forks source link

Short circuit queue feature #230

Closed aurum86 closed 2 years ago

basz commented 4 years ago

I like the idea, but am wondering if this could be complemented further;

Typical a Job gets pushed onto a queue without it's dependencies

public static function create(OrderId $orderId, CloudDriveContext $context): self
    {
        /** @var static $job */
        $job = (new \ReflectionClass(__CLASS__))->newInstanceWithoutConstructor();

        $job = $job->setContent([
            'order_id' => (string) $orderId,
            'context' => $context->toArray(),
        ]);

        return $job;
    }

// then

$queue->push(MyJob::create($orderId, $context));

When a Job is pulled from the queue it is recreated via a JobManager (service manager) and it's dependencies get injected. The AbstractQueue currently handles that.

Now; In your proposal you do an $job->execute() inside ShortCircuitQueue::push(). Obvious question is how did you instantiate the Job so it has it's dependencies?

Looking at SimpleQueue.php for inspiration and make it a real in-memory queue (Real in the sense it does serialising/unserialising and use the JobManager).

$queue->push(MyJob::create($orderId, $context));
$queue->push(MyJob::create($orderId, $context));
$queue->push(MyJob::create($orderId, $context));

while ($job = $queue->pop()) {
   $job->execute();
}

Final thought: normally the push and pop are both in different processes, which means application state and dependencies could be differ while debugging. Not very problematic in a monolithic application, but if you have a main application that pushes jobs and a slim worker application that consumes jobs that might become something that affect your debugging.