-
I have started to experiment with RoadRunner 2.11, and the HTTP server was pretty easy to set-up and worked almost out of the box. However, I'm now trying to get jobs working too, but when I try to check the availability of This is my RR dev config: version: '2.7'
server:
command: 'php ./bin/roadrunner-worker.php'
http:
address: '0.0.0.0:8080'
pool:
num_workers: 3
supervisor:
max_worker_memory: 100
jobs:
pool:
num_workers: 2
max_worker_memory: 100
timeout: 300
consume: ['myqueue']
pipelines:
myqueue:
driver: memory
config:
priority: 10
prefetch: 10
logs:
mode: development
channels:
http:
level: debug # Log all http requests, set to info to disable
server:
level: debug # Everything written to worker stderr is logged
metrics:
level: debug The <?php
declare(strict_types=1);
use Mezzio\Application;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileFactoryInterface;
use Spiral\RoadRunner\Http\PSR7Worker;
use Spiral\RoadRunner\Jobs\Consumer;
use Spiral\RoadRunner\Worker;
(static function (): void {
$rrMode = getenv('RR_MODE');
/** @var ContainerInterface $container */
$container = include __DIR__ . '/../config/container.php';
if ($rrMode === 'http') {
// This was spin-up as a web worker
$app = $container->get(Application::class);
$worker = new PSR7Worker(
Worker::create(),
$container->get(ServerRequestFactoryInterface::class),
$container->get(StreamFactoryInterface::class),
$container->get(UploadedFileFactoryInterface::class),
);
while ($req = $worker->waitRequest()) {
try {
$worker->respond($app->handle($req));
} catch (Throwable $e) {
$worker->getWorker()->error((string) $e);
}
}
} else {
// This was spin-up as a task worker
$consumer = new Consumer();
while ($task = $consumer->waitTask()) {
try {
var_dump($task);
$task->complete();
} catch (Throwable $e) {
$task->fail($e);
}
}
}
})(); At some point, in some HTTP request I do this (simplified): use Spiral\RoadRunner\Jobs\Jobs;
use Spiral\RoadRunner\Jobs\Serializer\JsonSerializer;
$jobs = new Jobs(null, new JsonSerializer());
if (! $jobs->isAvailable()) {
// It always ends up here.
// I debugged the isAvailable code and noticed it always ends inside the catch block with the error reported in the title
return;
}
$queue = $jobs->connect('myqueue');
$task = $queue->create(SomeEvent:class, [...]);
$queue->dispatch($task); If I remove the According to the docs, if the task is dispatched inside a RoadRunner worker (which is the case) I do not need to pass the connection settings, so I'm not sure what's missing. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hey @acelaya 👋🏻 https://github.com/roadrunner-server/roadrunner/blob/master/.rr.yaml#L19 |
Beta Was this translation helpful? Give feedback.
Hey @acelaya 👋🏻
You need to add the
RPC
plugin to the configuration because Jobs works over RPC.https://github.com/roadrunner-server/roadrunner/blob/master/.rr.yaml#L19