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); } }