diff --git a/src/Controller/AbstractWorkerController.php b/src/Controller/AbstractWorkerController.php deleted file mode 100644 index ddd6daa..0000000 --- a/src/Controller/AbstractWorkerController.php +++ /dev/null @@ -1,64 +0,0 @@ -worker = $worker; - $this->queuePluginManager = $queuePluginManager; - } - - public function processAction(): string - { - $options = $this->params()->fromRoute(); - $name = $options['queue']; - $queue = $this->queuePluginManager->get($name); - - try { - $messages = $this->worker->processQueue($queue, $options); - } catch (ExceptionInterface $e) { - throw new WorkerProcessException( - 'Caught exception while processing queue', - $e->getCode(), - $e - ); - } - - return $this->formatOutput($name, $messages); - } - - protected function formatOutput(string $queueName, array $messages = []): string - { - $messages = implode("\n", array_map(function (string $message): string { - return sprintf(' - %s', $message); - }, $messages)); - - return sprintf( - "Finished worker for queue '%s':\n%s\n", - $queueName, - $messages - ); - } -} diff --git a/tests/Asset/SimpleController.php b/tests/Asset/SimpleController.php deleted file mode 100644 index bc95ccb..0000000 --- a/tests/Asset/SimpleController.php +++ /dev/null @@ -1,12 +0,0 @@ -getEventManager(); - (new ProcessQueueStrategy())->attach($eventManager); - (new MaxRunsStrategy(['max_runs' => 1]))->attach($eventManager); - $serviceManager = new ServiceManager(); - $config = [ - 'factories' => [ - 'knownQueue' => SimpleQueueFactory::class, - ], - ]; - - $this->queuePluginManager = new QueuePluginManager($serviceManager, $config); - $this->controller = new SimpleController($worker, $this->queuePluginManager); - } - - public function testThrowExceptionIfQueueIsUnknown(): void - { - $routeMatch = new RouteMatch(['queue' => 'unknownQueue']); - $this->controller->getEvent()->setRouteMatch($routeMatch); - - $this->expectException(ServiceNotFoundException::class); - $this->controller->processAction(); - } - - public function testSimpleJob(): void - { - /** @var SimpleQueue $queue */ - $queue = $this->queuePluginManager->get('knownQueue'); - $queue->push(new SimpleJob()); - - $routeMatch = new RouteMatch(['queue' => 'knownQueue']); - $this->controller->getEvent()->setRouteMatch($routeMatch); - - $result = $this->controller->processAction(); - static::assertStringContainsString("Finished worker for queue 'knownQueue'", $result); - static::assertStringContainsString("maximum of 1 jobs processed", $result); - } - - public function testFailingJobThrowException(): void - { - /** @var SimpleQueue $queue */ - $queue = $this->queuePluginManager->get('knownQueue'); - $queue->push(new FailingJob()); - - $routeMatch = new RouteMatch(['queue' => 'knownQueue']); - $this->controller->getEvent()->setRouteMatch($routeMatch); - - $this->expectException(WorkerProcessException::class); - $this->controller->processAction(); - } -}