-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added WorkerRegistry and ability to add additional worker implementat… #98
Conversation
Hi @Baldinof 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 :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments. Great work :)
…ions (grpc, jobs, ...) stan fixes cs fix revert BC fix, deprecated GrpcWorkerInterface CS fix CS fix
edc9343
to
cb303de
Compare
@iborysenko would you mind adding full usage example to README ? |
Hi, you meant full roadrunner-jobs configuration, or symfony flex setup ? |
Aha, then I am looking forward to the next MR 😊 |
Thank you @iborysenko! |
It's awesome! |
…ions (grpc, jobs, ...)