Skip to content

Commit

Permalink
rename worker classes
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Jul 24, 2021
1 parent 37bf321 commit 50342cc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
16 changes: 8 additions & 8 deletions src/EventListener/WorkerListener.php
Expand Up @@ -23,10 +23,10 @@

use Fusio\Impl\Base;
use Fusio\Impl\Event;
use Fusio\Impl\Worker\Action\JavascriptWorker;
use Fusio\Impl\Worker\Action\JavaWorker;
use Fusio\Impl\Worker\Action\PHPWorker;
use Fusio\Impl\Worker\Action\PythonWorker;
use Fusio\Impl\Worker\Action\WorkerJavascript;
use Fusio\Impl\Worker\Action\WorkerJava;
use Fusio\Impl\Worker\Action\WorkerPHP;
use Fusio\Impl\Worker\Action\WorkerPython;
use Fusio\Model\Backend\Action_Config;
use Fusio\Model\Backend\Connection_Config;
use GuzzleHttp\Client;
Expand All @@ -43,10 +43,10 @@
class WorkerListener implements EventSubscriberInterface
{
private const MAPPING = [
JavascriptWorker::class => 'javascript',
JavaWorker::class => 'java',
PHPWorker::class => 'php',
PythonWorker::class => 'python',
WorkerJavascript::class => 'javascript',
WorkerJava::class => 'java',
WorkerPHP::class => 'php',
WorkerPython::class => 'python',
];

/**
Expand Down
15 changes: 10 additions & 5 deletions src/Worker/Action/WorkerAbstract.php
Expand Up @@ -31,6 +31,7 @@
use Fusio\Engine\RequestInterface;
use GuzzleHttp\Client;
use PSX\Framework\Config\Config;
use PSX\Http\Exception\InternalServerErrorException;

/**
* WorkerAbstract
Expand Down Expand Up @@ -63,7 +64,7 @@ public function handle(RequestInterface $request, ParametersInterface $configura
$endpoint = $worker[$this->getLanguage()] ?? null;

if (empty($endpoint)) {
throw new \RuntimeException('It looks like there is no worker configured for the language: ' . $this->getLanguage());
throw new \RuntimeException('It looks like there is no worker configured for the language: ' . $this->getLanguage() . '. More information about the worker system at: https://www.fusio-project.org/documentation/worker');
}

$response = $this->httpClient->post($endpoint . '/execute', [
Expand All @@ -72,9 +73,13 @@ public function handle(RequestInterface $request, ParametersInterface $configura

$data = \json_decode((string) $response->getBody());

if (isset($data->success) && $data->success === false) {
throw new InternalServerErrorException($data->message ?? 'An unknown error occurred at the worker');
}

if (isset($data->response)) {
$statusCode = $data->response->statusCode ?? 200;
$headers = $data->response->headers ?? [];
$statusCode = (int) ($data->response->statusCode ?? 200);
$headers = (array) ($data->response->headers ?? []);
$body = $data->response->body ?? new \stdClass();
} else {
throw new \RuntimeException('The worker does not return a response');
Expand Down Expand Up @@ -117,8 +122,8 @@ private function buildRequest(RequestInterface $request): array
return [
'method' => $request->getMethod(),
'headers' => $request->getHeaders(),
'uriFragments' => (object) $request->getUriFragments()->toArray(),
'parameters' => (object) $request->getParameters()->toArray(),
'uriFragments' => (object) $request->getUriFragments(),
'parameters' => (object) $request->getParameters(),
'body' => $request->getBody(),
];
} elseif ($request instanceof RpcInterface) {
Expand Down
Expand Up @@ -28,11 +28,11 @@
* @license http://www.gnu.org/licenses/agpl-3.0
* @link http://fusio-project.org
*/
class JavaWorker extends WorkerAbstract
class WorkerJava extends WorkerAbstract
{
public function getName()
{
return 'Java-Worker';
return 'Worker-Java';
}

protected function getLanguage(): string
Expand Down
Expand Up @@ -28,11 +28,11 @@
* @license http://www.gnu.org/licenses/agpl-3.0
* @link http://fusio-project.org
*/
class JavascriptWorker extends WorkerAbstract
class WorkerJavascript extends WorkerAbstract
{
public function getName()
{
return 'Javascript-Worker';
return 'Worker-Javascript';
}

protected function getLanguage(): string
Expand Down
Expand Up @@ -28,11 +28,11 @@
* @license http://www.gnu.org/licenses/agpl-3.0
* @link http://fusio-project.org
*/
class PHPWorker extends WorkerAbstract
class WorkerPHP extends WorkerAbstract
{
public function getName()
{
return 'PHP-Worker';
return 'Worker-PHP';
}

protected function getLanguage(): string
Expand Down
Expand Up @@ -28,11 +28,11 @@
* @license http://www.gnu.org/licenses/agpl-3.0
* @link http://fusio-project.org
*/
class PythonWorker extends WorkerAbstract
class WorkerPython extends WorkerAbstract
{
public function getName()
{
return 'Python-Worker';
return 'Worker-Python';
}

protected function getLanguage(): string
Expand Down

0 comments on commit 50342cc

Please sign in to comment.