From ecc67a43c8d10b6340951007abb12de5761a382d Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Tue, 24 Jun 2025 11:17:16 -0400 Subject: [PATCH] Service Worker, corre metodos de servicios asincronicamente, requiere parametros escalares y no retornar mas que bool o void --- app/src/Service/Worker/Service.php | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 app/src/Service/Worker/Service.php diff --git a/app/src/Service/Worker/Service.php b/app/src/Service/Worker/Service.php new file mode 100644 index 0000000..6c0e913 --- /dev/null +++ b/app/src/Service/Worker/Service.php @@ -0,0 +1,50 @@ +configuration; + $serviceClass = $configuration['service']; + $method = $configuration['method']; + $params = $configuration['params'] ?? []; + try { + $service = $this->container->get($serviceClass); + } catch (NotFoundExceptionInterface | ContainerExceptionInterface $exception) { + $this->logger->error($exception->getMessage()); + return false; + } + try { + $result = call_user_func_array([$service, $method], $params); + } catch (Exception $exception) { + $this->logger->error($exception->getMessage(), [ + 'Worker' => __CLASS__, + 'job_id' => $job->id, + 'service' => $serviceClass, + 'method' => $method, + 'params' => $params, + 'exception' => $exception + ]); + return false; + } + if (is_bool($result)) { + return $result; + } + return true; + } +} \ No newline at end of file