Skip to content

Commit

Permalink
add SelectableWorkerBootstrap (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mararok authored Sep 20, 2019
1 parent 7cf3547 commit eefc1d1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/SAREhub/DockerUtil/Worker/SelectableWorkerBootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php


namespace SAREhub\DockerUtil\Worker;


use Psr\Log\LogLevel;
use SAREhub\Commons\Logger\StreamLoggerFactoryProvider;
use SAREhub\Commons\Misc\EnvironmentHelper;

abstract class SelectableWorkerBootstrap
{
const ENV_WORKER_TYPE = "WORKER_TYPE";

public function run(): void
{
$workerType = strtoupper(EnvironmentHelper::getRequiredVar(self::ENV_WORKER_TYPE));
$factoryClass = $this->getWorkerContainerFactoryClassByType($workerType);
$errorHandler = $this->createUnexpectedErrorHandler();
WorkerBootstrap::create($factoryClass, $errorHandler)->run();
}

protected abstract function getWorkerContainerFactoryClassByType(string $type): string;

protected function createUnexpectedErrorHandler(): UnexpectedErrorHandler
{
$defaultLoggerFactory = (new StreamLoggerFactoryProvider(LogLevel::CRITICAL, null))->get();
return new DefaultUnexpectedErrorHandler($defaultLoggerFactory);
}
}

0 comments on commit eefc1d1

Please sign in to comment.