app = $app; $this->db = $db; $this->taskMutexService = $taskMutexService; $this->cycleJobService = $cycleJobService; $this->subscriptionModule = $subscriptionModule; } public function execute(): void { if ($this->taskMutexService->isTaskInstanceRunning('rechnungslauf_manual')) { return; } $this->taskMutexService->setMutex('rechnungslauf_manual'); $jobs = $this->cycleJobService->listAll(100); foreach ($jobs as $job) { try { switch ($job['document_type']) { case 'rechnung': $this->subscriptionModule->CreateInvoice((int)$job['address_id']); break; case 'auftrag': $this->subscriptionModule->CreateOrder((int)$job['address_id']); break; } } catch (Exception $e) { /** @var Logger $logger */ $logger = $this->app->Container->get('Logger'); $logger->error($e->getMessage(), $job); } finally { $this->cycleJobService->delete((int)$job['id']); } } } public function cleanup(): void { $this->taskMutexService->setMutex('rechnungslauf_manual', false); } }