Closed iborysenko closed 1 year ago
Hi @Baldinof This is preparation PR for future roadrunner/jobs integration
Now it will be possible to add something like
final class JobsWorker implements WorkerInterface
{
public function __construct(
private EventDispatcherInterface $eventDispatcher,
private ConsumerInterface $consumer,
private ProcessorRegistry $registry,
private ChainExceptionHandler $exceptionHandler
) {
}
public function start(): void
{
$this->eventDispatcher->dispatch(new WorkerStartEvent());
while ($task = $this->consumer->waitTask()) {
$this->eventDispatcher->dispatch(new TaskReceivedEvent($task));
$exception = null;
try {
$processor = $this->registry->getProcessor($task->getName());
if (!$processor instanceof ProcessorInterface) {
throw new JobsException(\sprintf('missing processor for task "%s"', $task->getName()));
}
$task = $processor->process($task);
} catch (\Throwable $e) {
$exception = $e;
$task = $this->exceptionHandler->handle($exception, $task);
} finally {
if (false === $task->isCompleted()) {
$task->complete();
}
$this->eventDispatcher->dispatch(new TaskCompletedEvent($task, $exception));
}
}
$this->eventDispatcher->dispatch(new WorkerStopEvent());
}
}
Hi!
Nice, I'll try to review it this week :)
@iborysenko would you mind adding full usage example to README ?
FluffyDiscord
Hi, you meant full roadrunner-jobs configuration, or symfony flex setup ? My implementation of roadrunner-jobs will be in the next MR, this MR is just structure preparation
FluffyDiscord
Hi, you meant full roadrunner-jobs configuration, or symfony flex setup ? My implementation of roadrunner-jobs will be in the next MR, this MR is just structure preparation
Aha, then I am looking forward to the next MR 😊
Thank you @iborysenko!
It's awesome! Waiting for release!
…ions (grpc, jobs, ...)