eee
This commit is contained in:
+6
-10
@@ -72,19 +72,15 @@ class Task
|
||||
*/
|
||||
public function onTask(Server $server, int $task_id, int $src_worker_id, mixed $data): void
|
||||
{
|
||||
$response = 'task data format failed.';
|
||||
try {
|
||||
$data = json_decode($data, true);
|
||||
if (!is_null($data)) {
|
||||
[$handler, $params] = [$data[0], $data[1]];
|
||||
[$handler, $params] = [$data[0], $data[1]];
|
||||
|
||||
$handler = Kiri::getDi()->make($handler, $params);
|
||||
if (!($handler instanceof OnTaskInterface)) {
|
||||
throw new \Exception('Task process must implements ' . OnTaskInterface::class);
|
||||
}
|
||||
|
||||
$response = call_user_func([$handler, 'process'], $task_id, $src_worker_id);
|
||||
$handler = Kiri::getDi()->make($handler, $params);
|
||||
if (!($handler instanceof OnTaskInterface)) {
|
||||
throw new \Exception('Task process must implements ' . OnTaskInterface::class);
|
||||
}
|
||||
|
||||
$response = call_user_func([$handler, 'process'], $task_id, $src_worker_id);
|
||||
} catch (\Throwable $throwable) {
|
||||
$response = throwable($throwable);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user