service = $service; $this->entityManager = $entityManager; } public function run(Data $data): void { $targetId = $data->getTargetId(); if (!$targetId) { throw new Error("No target."); } $entity = $this->entityManager->getEntity('InboundEmail', $targetId); if (!$entity) { throw new Error("Job CheckInboundEmails '{$targetId}': InboundEmail does not exist.", -1); } if ($entity->get('status') !== 'Active') { throw new Error("Job CheckInboundEmails '{$targetId}': InboundEmail is not active.", -1); } try { $this->service->fetchFromMailServer($entity); } catch (Throwable $e) { throw new Error( 'Job CheckInboundEmails ' . $entity->getId() . ': [' . $e->getCode() . '] ' .$e->getMessage() ); } } }