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

Commit

Permalink
Merge pull request #105 from rokde/master
Browse files Browse the repository at this point in the history
shared network for queue worker
  • Loading branch information
Robert Kummer authored Nov 28, 2019
2 parents c8e57ed + 0b9be15 commit e127553
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Rancherize\Blueprint\Infrastructure\Service\Events;

use Rancherize\Blueprint\Infrastructure\Service\Services\LaravelQueueWorker;
use Rancherize\Configuration\Configuration;
use Symfony\Component\EventDispatcher\Event;

class QueueWorkerBuiltEvent extends Event
{
const NAME = 'queue.worker.built';

/** @var \Rancherize\Blueprint\Infrastructure\Service\Services\LaravelQueueWorker */
private $queueWorker;
/** @var \Rancherize\Configuration\Configuration */
private $environmentConfiguration;
/** @var \Rancherize\Configuration\Configuration */
private $queueConfiguration;

public function __construct(
LaravelQueueWorker $queueWorker,
Configuration $environmentConfiguration,
Configuration $queueConfiguration
) {
$this->queueWorker = $queueWorker;
$this->environmentConfiguration = $environmentConfiguration;
$this->queueConfiguration = $queueConfiguration;
}

public function getQueueWorker(): \Rancherize\Blueprint\Infrastructure\Service\Services\LaravelQueueWorker
{
return $this->queueWorker;
}

public function getEnvironmentConfiguration(): \Rancherize\Configuration\Configuration
{
return $this->environmentConfiguration;
}

public function getQueueConfiguration(): \Rancherize\Configuration\Configuration
{
return $this->queueConfiguration;
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Rancherize\Blueprint\Infrastructure\Service\Services;

use Rancherize\Blueprint\Infrastructure\Service\NetworkMode\ShareNetworkMode;
use Rancherize\Blueprint\Infrastructure\Service\Service;

/**
Expand Down Expand Up @@ -30,7 +31,11 @@ public function __construct($imageVersion = null)
$this->setRestart(self::RESTART_UNLESS_STOPPED);
}

public function setImageVersion($version)
public function setParent(Service $service) {
$this->setNetworkMode(new ShareNetworkMode($service));
}

public function setImageVersion($version)
{
if ($version === null) {
$this->setImage('ipunktbs/laravel-queue-worker:' . self::DEFAULT_IMAGE_VERSION);
Expand Down
2 changes: 1 addition & 1 deletion app/Blueprint/Webserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ This blueprint creates infrastructures to support apps using php7.

##### Queue Worker

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`.
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.

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.

Expand Down
5 changes: 5 additions & 0 deletions app/Blueprint/Webserver/WebserverBlueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Rancherize\Blueprint\Healthcheck\HealthcheckInitService\HealthcheckInitService;
use Rancherize\Blueprint\Infrastructure\Dockerfile\Dockerfile;
use Rancherize\Blueprint\Infrastructure\Infrastructure;
use Rancherize\Blueprint\Infrastructure\Service\Events\QueueWorkerBuiltEvent;
use Rancherize\Blueprint\Infrastructure\Service\Maker\CustomFiles\CustomFilesTrait;
use Rancherize\Blueprint\Infrastructure\Service\Maker\PhpFpm\PhpFpmMakerTrait;
use Rancherize\Blueprint\Infrastructure\Service\Service;
Expand Down Expand Up @@ -567,6 +568,7 @@ protected function addQueueWorker(Configuration $config, Service $serverService,
$queues = $config->get('queues', []);
$queueImageVersion = $config->get('queue-image-version', null);
foreach ($queues as $key => $queue) {
$queueConfig = new PrefixConfigurationDecorator($config, "queues.$key.");
$name = $config->get("queues.$key.name", 'default');
$connection = $config->get("queues.$key.connection", 'default');
$memoryLimit = intval($config->get("queues.$key.memory-limit", self::DEFAULT_PHP_MEMORY_LIMIT));
Expand All @@ -586,9 +588,12 @@ protected function addQueueWorker(Configuration $config, Service $serverService,
$laravelQueueWorker->setEnvironmentVariable('LARAVEL_HORIZON', true);
}
$laravelQueueWorker->setEnvironmentVariable('PHP_MEMORY_LIMIT', $memoryLimit);
$laravelQueueWorker->setParent($serverService);

$serverService->addSidekick($laravelQueueWorker);
$infrastructure->addService($laravelQueueWorker);

$this->event->dispatch(QueueWorkerBuiltEvent::NAME, new QueueWorkerBuiltEvent($laravelQueueWorker, $config, $queueConfig));
}
}

Expand Down

0 comments on commit e127553

Please sign in to comment.