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

Commit

Permalink
queue worker shared network
Browse files Browse the repository at this point in the history
queue worker built event added
  • Loading branch information
Robert Kummer committed Nov 28, 2019
1 parent 1727328 commit 0b9be15
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
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
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 0b9be15

Please sign in to comment.