From 86d1111f54ce5c83c455fb05fab56783e417a815 Mon Sep 17 00:00:00 2001 From: Molly Date: Fri, 5 May 2023 11:55:15 +0100 Subject: [PATCH 1/2] Change Final Methods to Protected Changed to allow method overrides to facilitate error handling in jobfinder --- src/Commands/PushDeletedToCyclopsCommand.php | 2 +- src/Commands/PushStaleToCyclopsCommand.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Commands/PushDeletedToCyclopsCommand.php b/src/Commands/PushDeletedToCyclopsCommand.php index 6302c36..7679728 100644 --- a/src/Commands/PushDeletedToCyclopsCommand.php +++ b/src/Commands/PushDeletedToCyclopsCommand.php @@ -6,7 +6,7 @@ abstract class PushDeletedToCyclopsCommand extends PushStateToCyclopsCommand { - final function executeUseCase() + protected function executeUseCase() { $pushUseCase = new PushDeletedToCyclopsUseCase($this->getService()); $pushUseCase->execute($this->getList(), $this->onCustomerDeleted()); diff --git a/src/Commands/PushStaleToCyclopsCommand.php b/src/Commands/PushStaleToCyclopsCommand.php index 1007be1..91f73dc 100644 --- a/src/Commands/PushStaleToCyclopsCommand.php +++ b/src/Commands/PushStaleToCyclopsCommand.php @@ -6,7 +6,7 @@ abstract class PushStaleToCyclopsCommand extends PushStateToCyclopsCommand { - final function executeUseCase() + protected function executeUseCase() { $pushUseCase = new PushStaleToCyclopsUseCase($this->getService()); $pushUseCase->execute($this->getList(), $this->getCustomerPushedHandler()); From f6b9a52e8a5e3b9b22f175aa0d859acfd286b105 Mon Sep 17 00:00:00 2001 From: Molly Date: Wed, 6 Sep 2023 14:39:35 +0100 Subject: [PATCH 2/2] Throw new CyclopsException for deleted user not found Throw a CyclopsException when a CustomerNotFoundException is caught so that we can retry the request and/or send the failure email. Also added some clarifying comments. --- src/UseCases/PushDeletedToCyclopsUseCase.php | 10 ++++++++++ src/UseCases/PushStaleToCyclopsUseCase.php | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/UseCases/PushDeletedToCyclopsUseCase.php b/src/UseCases/PushDeletedToCyclopsUseCase.php index 151f989..5993cdf 100644 --- a/src/UseCases/PushDeletedToCyclopsUseCase.php +++ b/src/UseCases/PushDeletedToCyclopsUseCase.php @@ -24,12 +24,22 @@ public function execute(CyclopsCustomerListEntity $list, callable $onCustomerDel foreach ($list->items as $item) { try { $this->cyclopsService->deleteCustomer($item->identity, $item->timestamp); + if ($onCustomerDeleted !== null) { + // Set CyclopsQueue item to sent $onCustomerDeleted($item, true); } } catch (CustomerNotFoundException $exception) { if ($onCustomerDeleted !== null) { + // Set CyclopsQueue item to not sent $onCustomerDeleted($item, false); + + // Throw new exception to trigger retry request and/or failure email + throw new CyclopsException( + "404 Customer Not Found and queue item not sent", + 404, + $exception + ); } } } diff --git a/src/UseCases/PushStaleToCyclopsUseCase.php b/src/UseCases/PushStaleToCyclopsUseCase.php index da86ab8..938c19a 100644 --- a/src/UseCases/PushStaleToCyclopsUseCase.php +++ b/src/UseCases/PushStaleToCyclopsUseCase.php @@ -26,12 +26,15 @@ public function execute(CyclopsCustomerListEntity $list, callable $onItemPushed) throw new CustomerNotFoundException(); } $this->cyclopsService->setBrandOptInStatus($item); + + // Set CyclopsQueue item to not sent $onItemPushed($item, false); } catch (CustomerNotFoundException $exception) { $customer = $this->cyclopsService->loadCustomer($item->identity, $item->timestamp); $customer->brandOptIn = $item->brandOptIn; $this->cyclopsService->setBrandOptInStatus($customer); + // Set CyclopsQueue item to sent $onItemPushed($item, true, $customer); } }