Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit e127553

Browse files
author
Robert Kummer
authored
Merge pull request #105 from rokde/master
shared network for queue worker
2 parents c8e57ed + 0b9be15 commit e127553

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Rancherize\Blueprint\Infrastructure\Service\Events;
4+
5+
use Rancherize\Blueprint\Infrastructure\Service\Services\LaravelQueueWorker;
6+
use Rancherize\Configuration\Configuration;
7+
use Symfony\Component\EventDispatcher\Event;
8+
9+
class QueueWorkerBuiltEvent extends Event
10+
{
11+
const NAME = 'queue.worker.built';
12+
13+
/** @var \Rancherize\Blueprint\Infrastructure\Service\Services\LaravelQueueWorker */
14+
private $queueWorker;
15+
/** @var \Rancherize\Configuration\Configuration */
16+
private $environmentConfiguration;
17+
/** @var \Rancherize\Configuration\Configuration */
18+
private $queueConfiguration;
19+
20+
public function __construct(
21+
LaravelQueueWorker $queueWorker,
22+
Configuration $environmentConfiguration,
23+
Configuration $queueConfiguration
24+
) {
25+
$this->queueWorker = $queueWorker;
26+
$this->environmentConfiguration = $environmentConfiguration;
27+
$this->queueConfiguration = $queueConfiguration;
28+
}
29+
30+
public function getQueueWorker(): \Rancherize\Blueprint\Infrastructure\Service\Services\LaravelQueueWorker
31+
{
32+
return $this->queueWorker;
33+
}
34+
35+
public function getEnvironmentConfiguration(): \Rancherize\Configuration\Configuration
36+
{
37+
return $this->environmentConfiguration;
38+
}
39+
40+
public function getQueueConfiguration(): \Rancherize\Configuration\Configuration
41+
{
42+
return $this->queueConfiguration;
43+
}
44+
45+
46+
}

app/Blueprint/Infrastructure/Service/Services/LaravelQueueWorker.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace Rancherize\Blueprint\Infrastructure\Service\Services;
22

3+
use Rancherize\Blueprint\Infrastructure\Service\NetworkMode\ShareNetworkMode;
34
use Rancherize\Blueprint\Infrastructure\Service\Service;
45

56
/**
@@ -30,7 +31,11 @@ public function __construct($imageVersion = null)
3031
$this->setRestart(self::RESTART_UNLESS_STOPPED);
3132
}
3233

33-
public function setImageVersion($version)
34+
public function setParent(Service $service) {
35+
$this->setNetworkMode(new ShareNetworkMode($service));
36+
}
37+
38+
public function setImageVersion($version)
3439
{
3540
if ($version === null) {
3641
$this->setImage('ipunktbs/laravel-queue-worker:' . self::DEFAULT_IMAGE_VERSION);

app/Blueprint/Webserver/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ This blueprint creates infrastructures to support apps using php7.
6565

6666
##### Queue Worker
6767

68-
You can use [Laravel Horizon](https://laravel.com/docs/horizon) by setting a config key `horizon` to a boolean value. If true the queue worker needs laravel horizon in your source code and runs horizon command instead of `queue:work`.
68+
You can use [Laravel Horizon](https://laravel.com/docs/horizon) by setting a config key `horizon` to a boolean value. If true the queue worker needs laravel horizon in your source code and runs horizon command instead of `queue:work`. For Horizon you need version `php7.3-v4.4` at least to work correctly.
6969

7070
Since queue image version `php7.3-v4.1` you can set an key `memory-limit` for each queue entry. It defaults to `512` and sets the limit to MB. The `-1` is for unlimited memory usage.
7171

app/Blueprint/Webserver/WebserverBlueprint.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Rancherize\Blueprint\Healthcheck\HealthcheckInitService\HealthcheckInitService;
1212
use Rancherize\Blueprint\Infrastructure\Dockerfile\Dockerfile;
1313
use Rancherize\Blueprint\Infrastructure\Infrastructure;
14+
use Rancherize\Blueprint\Infrastructure\Service\Events\QueueWorkerBuiltEvent;
1415
use Rancherize\Blueprint\Infrastructure\Service\Maker\CustomFiles\CustomFilesTrait;
1516
use Rancherize\Blueprint\Infrastructure\Service\Maker\PhpFpm\PhpFpmMakerTrait;
1617
use Rancherize\Blueprint\Infrastructure\Service\Service;
@@ -567,6 +568,7 @@ protected function addQueueWorker(Configuration $config, Service $serverService,
567568
$queues = $config->get('queues', []);
568569
$queueImageVersion = $config->get('queue-image-version', null);
569570
foreach ($queues as $key => $queue) {
571+
$queueConfig = new PrefixConfigurationDecorator($config, "queues.$key.");
570572
$name = $config->get("queues.$key.name", 'default');
571573
$connection = $config->get("queues.$key.connection", 'default');
572574
$memoryLimit = intval($config->get("queues.$key.memory-limit", self::DEFAULT_PHP_MEMORY_LIMIT));
@@ -586,9 +588,12 @@ protected function addQueueWorker(Configuration $config, Service $serverService,
586588
$laravelQueueWorker->setEnvironmentVariable('LARAVEL_HORIZON', true);
587589
}
588590
$laravelQueueWorker->setEnvironmentVariable('PHP_MEMORY_LIMIT', $memoryLimit);
591+
$laravelQueueWorker->setParent($serverService);
589592

590593
$serverService->addSidekick($laravelQueueWorker);
591594
$infrastructure->addService($laravelQueueWorker);
595+
596+
$this->event->dispatch(QueueWorkerBuiltEvent::NAME, new QueueWorkerBuiltEvent($laravelQueueWorker, $config, $queueConfig));
592597
}
593598
}
594599

0 commit comments

Comments
 (0)