From 6bc93e9a9413bde3a55a374b2bb7db7e0186c7ac Mon Sep 17 00:00:00 2001 From: aynsix Date: Tue, 9 Jul 2024 15:24:02 +0300 Subject: [PATCH] add a return value --- .../Command/WorkerRunServiceCommand.php | 5 +++-- .../WorkerManager/Worker/AssetsIngestWorker.php | 4 +++- .../WorkerManager/Worker/CreateRecordWorker.php | 8 +++++--- .../WorkerManager/Worker/EditRecordWorker.php | 8 +++++--- .../WorkerManager/Worker/ExposeUploadWorker.php | 10 ++++++---- .../Phrasea/WorkerManager/Worker/FtpWorker.php | 8 ++++++-- .../WorkerManager/Worker/PopulateIndexWorker.php | 4 +++- .../Worker/SubdefCreationWorker.php | 14 ++++++++------ .../Worker/WriteMetadatasWorker.php | 16 +++++++++------- 9 files changed, 48 insertions(+), 29 deletions(-) diff --git a/lib/Alchemy/Phrasea/WorkerManager/Command/WorkerRunServiceCommand.php b/lib/Alchemy/Phrasea/WorkerManager/Command/WorkerRunServiceCommand.php index ae26d8c9d9..e589a20115 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Command/WorkerRunServiceCommand.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Command/WorkerRunServiceCommand.php @@ -39,14 +39,14 @@ protected function doExecute(InputInterface $input, OutputInterface $output) if ($body === false) { $output->writeln(sprintf('Unable to read payload file %s', $input->getArgument('body'))); - return; + return 0; } $body = json_decode($body, true); if (json_last_error() !== JSON_ERROR_NONE) { $output->writeln('Invalid message body'); - return; + return 0; } } @@ -58,5 +58,6 @@ protected function doExecute(InputInterface $input, OutputInterface $output) @unlink($input->getArgument('body')); } + return 0; } } diff --git a/lib/Alchemy/Phrasea/WorkerManager/Worker/AssetsIngestWorker.php b/lib/Alchemy/Phrasea/WorkerManager/Worker/AssetsIngestWorker.php index 8d30b5baff..eeba795f6a 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Worker/AssetsIngestWorker.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Worker/AssetsIngestWorker.php @@ -71,7 +71,7 @@ public function process(array $payload) $count )); - return; + return 0; } $body = json_decode($body,true); @@ -111,6 +111,8 @@ public function process(array $payload) unset($workerRunningJob); } $em->flush(); + + return 0; } private function createStory(array $body) diff --git a/lib/Alchemy/Phrasea/WorkerManager/Worker/CreateRecordWorker.php b/lib/Alchemy/Phrasea/WorkerManager/Worker/CreateRecordWorker.php index 03847d2fa2..6c197cd9c9 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Worker/CreateRecordWorker.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Worker/CreateRecordWorker.php @@ -116,7 +116,7 @@ public function process(array $payload) $workerRunningJob->getId() )); - return; + return 0; } @@ -134,7 +134,7 @@ public function process(array $payload) $workerRunningJob->getId() )); - return; + return 0; } if ($workerRunningJob != null) { @@ -181,7 +181,7 @@ public function process(array $payload) if (!isset($body['formData']['collection_destination'])) { $this->messagePublisher->pushLog("The collection_destination is not defined"); - return ; + return 0; } $base_id = $body['formData']['collection_destination']; @@ -257,6 +257,8 @@ public function process(array $payload) ] ] ); + + return 0; } /** diff --git a/lib/Alchemy/Phrasea/WorkerManager/Worker/EditRecordWorker.php b/lib/Alchemy/Phrasea/WorkerManager/Worker/EditRecordWorker.php index 0997204cf5..d54b484209 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Worker/EditRecordWorker.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Worker/EditRecordWorker.php @@ -34,7 +34,7 @@ public function process(array $payload) try { $databox = $this->findDataboxById($payload['databoxId']); } catch(\Exception $e) { - return; + return 0; } $recordIds = []; @@ -49,7 +49,7 @@ public function process(array $payload) if ($workerRunningJob == null) { $this->messagePublisher->pushLog("Given workerJobId not found !", 'error'); - return ; + return 0; } $workerRunningJob @@ -191,7 +191,7 @@ public function process(array $payload) $workerMessage ); - return; + return 0; } // order to write metas for those records @@ -213,5 +213,7 @@ public function process(array $payload) } $this->messagePublisher->pushLog(sprintf("record edited databoxname=%s databoxid=%d recordid=%d", $databox->get_viewname(), $payload['databoxId'], $payload['record_id'])); + + return 0; } } diff --git a/lib/Alchemy/Phrasea/WorkerManager/Worker/ExposeUploadWorker.php b/lib/Alchemy/Phrasea/WorkerManager/Worker/ExposeUploadWorker.php index 1050e8df37..1da536a75d 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Worker/ExposeUploadWorker.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Worker/ExposeUploadWorker.php @@ -49,7 +49,7 @@ public function process(array $payload) if ($workerRunningJob == null) { $this->messagePublisher->pushLog("Given workerJobId not found !", 'error'); - return ; + return 0; } $workerRunningJob @@ -243,7 +243,7 @@ public function process(array $payload) $this->messagePublisher->pushLog(sprintf("subdefinition %s or file as document mapping not found", $phraseanetSubdefAsDocument)); $this->finishedJob($workerRunningJob, $em, WorkerRunningJob::ERROR); - return ; + return 0; } if ($lat !== null) { @@ -271,7 +271,7 @@ public function process(array $payload) $this->messagePublisher->pushLog("An error occurred when creating asset: status-code " . $response->getStatusCode()); $this->finishedJob($workerRunningJob, $em, WorkerRunningJob::ERROR); - return ; + return 0; } $assetsResponse = json_decode($response->getBody(),true); @@ -369,11 +369,13 @@ public function process(array $payload) $this->messagePublisher->pushLog("An error occurred when creating asset!: ". $e->getMessage()); $this->finishedJob($workerRunningJob, $em, WorkerRunningJob::ERROR); - return; + return 0; } // tell that the upload is finished $this->finishedJob($workerRunningJob, $em); + + return 0; } private function getClientAnnotationProfile(Client $exposeClient, $publicationId) diff --git a/lib/Alchemy/Phrasea/WorkerManager/Worker/FtpWorker.php b/lib/Alchemy/Phrasea/WorkerManager/Worker/FtpWorker.php index 6db13c3bd9..ec6218a13b 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Worker/FtpWorker.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Worker/FtpWorker.php @@ -47,8 +47,10 @@ public function process(array $payload) $export = $repoFtpExport->find($payload['ftpExportId']); if ($export !== null) { - $this->doExport($export, $payload); + return $this->doExport($export, $payload); } + + return 0; } private function doExport(FtpExport $export, array $payload) @@ -73,7 +75,7 @@ private function doExport(FtpExport $export, array $payload) if ($workerRunningJob == null) { $this->logger->error("Given workerJobId not found !"); - return ; + return 0; } $workerRunningJob @@ -401,6 +403,8 @@ private function doExport(FtpExport $export, array $payload) $workerMessage ); } + + return 0; } private function finalize(Application $app, FtpExport $export) diff --git a/lib/Alchemy/Phrasea/WorkerManager/Worker/PopulateIndexWorker.php b/lib/Alchemy/Phrasea/WorkerManager/Worker/PopulateIndexWorker.php index 465599fae9..ec7499b650 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Worker/PopulateIndexWorker.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Worker/PopulateIndexWorker.php @@ -45,7 +45,7 @@ public function process(array $payload) if ($workerRunningJob == null) { $this->messagePublisher->pushLog("Given workerJobId not found !", "error"); - return ; + return 0; } $workerRunningJob @@ -155,6 +155,8 @@ public function process(array $payload) $em->flush(); } + + return 0; } } diff --git a/lib/Alchemy/Phrasea/WorkerManager/Worker/SubdefCreationWorker.php b/lib/Alchemy/Phrasea/WorkerManager/Worker/SubdefCreationWorker.php index 9e647191f6..82a782137d 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Worker/SubdefCreationWorker.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Worker/SubdefCreationWorker.php @@ -61,7 +61,7 @@ public function process(array $payload) if (!isset($payload['recordId']) || !isset($payload['databoxId']) || !isset($payload['subdefName'])) { // bad payload $this->logger->error(sprintf("%s (%s) : bad payload", __FILE__, __LINE__)); - return; + return 0; } $recordId = $payload['recordId']; @@ -74,11 +74,11 @@ public function process(array $payload) } catch (\Exception $e) { $this->logger->error(sprintf("%s (%s) : record not found %s", __FILE__, __LINE__, $e->getMessage())); - return; + return 0; } if ($record->isStory()) { - return; + return 0; } $oldLogger = $this->subdefGenerator->getLogger(); @@ -96,7 +96,7 @@ public function process(array $payload) MessagePublisher::SUBDEF_CREATION_TYPE ); - return ; + return 0; } // here we can work @@ -130,7 +130,7 @@ public function process(array $payload) )); // the subscriber will "unlock" the row, no need to do it here - return ; + return 0; } // begin to check if the subdef is successfully generated @@ -158,7 +158,7 @@ public function process(array $payload) $this->subdefGenerator->setLogger($oldLogger); // the subscriber will "unlock" the row, no need to do it here - return ; + return 0; } // checking ended @@ -202,6 +202,8 @@ public function process(array $payload) $this->repoWorker->markFinished($workerRunningJobId); $this->getDataboxLogger($databox)->initOrUpdateLogDocsFromWorker($record, $databox, $workerRunningJob, $subdefName, \Session_Logger::EVENT_SUBDEFCREATION, new \DateTime('now'), WorkerRunningJob::FINISHED); + + return 0; } public static function checkIfFirstChild(\record_adapter $story, \record_adapter $record) diff --git a/lib/Alchemy/Phrasea/WorkerManager/Worker/WriteMetadatasWorker.php b/lib/Alchemy/Phrasea/WorkerManager/Worker/WriteMetadatasWorker.php index a32ceadce7..2bbec6986c 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Worker/WriteMetadatasWorker.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Worker/WriteMetadatasWorker.php @@ -64,7 +64,7 @@ public function process(array $payload) if (!isset($payload['recordId']) || !isset($payload['databoxId']) || !isset($payload['subdefName'])) { // bad payload $this->logger->error(sprintf("%s (%s) : bad payload", __FILE__, __LINE__)); - return; + return 0; } $databoxId = $payload['databoxId']; @@ -88,7 +88,7 @@ public function process(array $payload) MessagePublisher::WRITE_METADATAS_TYPE ); - return ; + return 0; } // here we can work @@ -98,7 +98,7 @@ public function process(array $payload) } catch (\Exception $e) { $this->repoWorker->markFinished($workerRunningJobId, "error " . $e->getMessage()); - return; + return 0; } /** @var WorkerRunningJob $workerRunningJob */ @@ -116,7 +116,7 @@ public function process(array $payload) $this->getDataboxLogger($databox)->initOrUpdateLogDocsFromWorker($record, $databox, $workerRunningJob, $subdefName, \Session_Logger::EVENT_WRITEMETADATAS, new \DateTime('now'), WorkerRunningJob::ERROR); - return; + return 0; } $this->repoWorker->reconnect(); @@ -141,7 +141,7 @@ public function process(array $payload) )); // the subscriber will mark the job as errored, no need to do it here - return ; + return 0; } if (!$subdef->is_physically_present()) { @@ -158,7 +158,7 @@ public function process(array $payload) )); // the subscriber will mark the job as errored, no need to do it here - return ; + return 0; } // here we can try to do the job @@ -326,7 +326,7 @@ public function process(array $payload) $this->repoWorker->markFinished($workerRunningJobId, $stopInfo); $this->getDataboxLogger($databox)->initOrUpdateLogDocsFromWorker($record, $databox, $workerRunningJob, $subdefName, \Session_Logger::EVENT_WRITEMETADATAS, new \DateTime('now'), WorkerRunningJob::ERROR); } - return ; + return 0; } // mark write metas finished @@ -336,6 +336,8 @@ public function process(array $payload) $this->repoWorker->markFinished($workerRunningJobId); $this->getDataboxLogger($databox)->initOrUpdateLogDocsFromWorker($record, $databox, $workerRunningJob, $subdefName, \Session_Logger::EVENT_WRITEMETADATAS, new \DateTime('now'), WorkerRunningJob::FINISHED); + + return 0; } private function removeNulChar($value)