From 4ce6742d41c9dcb5f6055090af9f64e3e11007c7 Mon Sep 17 00:00:00 2001 From: Alex Berryman Date: Thu, 5 Mar 2020 15:20:07 -0600 Subject: [PATCH] implement reload() method and mark it as deprecated --- src/Api/V1/Worker/Service.php | 20 ++++++++++++++++++-- src/Api/V1/Worker/ServiceInterface.php | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Api/V1/Worker/Service.php b/src/Api/V1/Worker/Service.php index aa9c6dc4..af88ef49 100644 --- a/src/Api/V1/Worker/Service.php +++ b/src/Api/V1/Worker/Service.php @@ -3,14 +3,14 @@ namespace Neighborhoods\Kojo\Api\V1\Worker; +use Neighborhoods\Kojo\Api; use Neighborhoods\Kojo\Api\V1\Job\SchedulerInterface; use Neighborhoods\Kojo\Api\V1\LoggerInterface; use Neighborhoods\Kojo\Apm; use Neighborhoods\Kojo\Data\Job; +use Neighborhoods\Kojo\Service\Create; use Neighborhoods\Kojo\Service\Update; -use Neighborhoods\Kojo\Api; use Neighborhoods\Pylon\Data\Property\Defensive; -use Neighborhoods\Kojo\Service\Create; class Service implements ServiceInterface { @@ -102,6 +102,17 @@ public function applyRequest(): ServiceInterface throw new \UnexpectedValueException('Unexpected value[' . $this->_read(self::PROP_REQUEST) . '].'); } $this->_create(self::PROP_REQUEST_APPLIED, true); + } else { + $this->getLogger()->alert( + 'applyRequest was called repeatedly', + [ + 'requested_state' => $this->_read(self::PROP_REQUEST), + ] + ); + // Reload the state from the database + $this->reload(); + // Apply the request and allow the State Service to complain if it is an invalid transition + $this->applyRequest(); } return $this; @@ -122,8 +133,13 @@ public function getLogger(): LoggerInterface return $this->getApiV1Logger(); } + /** @deprecated */ public function reload(): ServiceInterface { + $newJob = $this->_getJob()->load(); + $this->_unsetJob(); + $this->setJob($newJob); + $this->_delete(self::PROP_REQUEST_APPLIED); return $this; } diff --git a/src/Api/V1/Worker/ServiceInterface.php b/src/Api/V1/Worker/ServiceInterface.php index 307be786..634a54c3 100644 --- a/src/Api/V1/Worker/ServiceInterface.php +++ b/src/Api/V1/Worker/ServiceInterface.php @@ -30,6 +30,7 @@ public function getLogger(): LoggerInterface; public function getNewJobScheduler(): SchedulerInterface; + /** @deprecated */ public function reload(): ServiceInterface; public function getTimesCrashed(): int;