Skip to content

Commit

Permalink
Remove worker concept
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldiron committed Jan 4, 2024
1 parent d5e2929 commit ee4fc6d
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 60 deletions.
1 change: 0 additions & 1 deletion src/Http/Adapter.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
abstract class Adapter
{
abstract public function onStart(callable $callback);
abstract public function onWorkerStart(callable $callback);
abstract public function onRequest(callable $callback);
abstract public function start();
}
5 changes: 0 additions & 5 deletions src/Http/Adapter/FPM/Server.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public function onStart(callable $callback)
call_user_func($callback, $this);
}

public function onWorkerStart(callable $callback)
{
call_user_func($callback, $this);
}

public function start()
{
return;
Expand Down
5 changes: 0 additions & 5 deletions src/Http/Adapter/Swoole/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public function onRequest(callable $callback)
});
}

public function onWorkerStart(callable $callback)
{
call_user_func($callback, $this);
}

public function onStart(callable $callback)
{
call_user_func($callback, $this);
Expand Down
49 changes: 0 additions & 49 deletions src/Http/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ class Http
*/
protected static array $startHooks = [];

/**
* Worker Start hooks
*
* @var Hook[]
*/
protected static array $workerStartHooks = [];

/**
* Request hooks
*
Expand Down Expand Up @@ -563,13 +556,6 @@ protected function getFileMimeType(string $uri): mixed
return $this->files->getFileMimeType($uri);
}

public static function onWorkerStart(): Hook
{
$hook = new Hook();
self::$workerStartHooks[] = $hook;
return $hook;
}

public static function onStart(): Hook
{
$hook = new Hook();
Expand Down Expand Up @@ -623,40 +609,6 @@ public function start()
}
});

$this->server->onWorkerStart(function ($server, $workerId) {
$this->resources['utopia'] ??= [];
$this->resources['utopia']['server'] = $server;
$this->resources['utopia']['workerId'] = $workerId;

self::setResource('server', function () use ($server) {
return $server;
});
self::setResource('workerId', function () use ($workerId) {
return $workerId;
});

try {

foreach (self::$workerStartHooks as $hook) {
$arguments = $this->getArguments($hook, 'utopia', [], []);
\call_user_func_array($hook->getAction(), $arguments);
}
} catch(\Exception $e) {
self::setResource('error', fn () => $e);

foreach (self::$errors as $error) { // Global error hooks
if (in_array('*', $error->getGroups())) {
try {
$arguments = $this->getArguments($error, 'utopia', [], []);
\call_user_func_array($error->getAction(), $arguments);
} catch (\Throwable $e) {
throw new Exception('Error handler had an error: ' . $e->getMessage(), 500, $e);
}
}
}
}
});

$this->server->start();
}

Expand Down Expand Up @@ -1004,7 +956,6 @@ public static function reset(): void
self::$init = [];
self::$shutdown = [];
self::$options = [];
self::$workerStartHooks = [];
self::$startHooks = [];
}
}

0 comments on commit ee4fc6d

Please sign in to comment.