mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-12-25 14:10:28 +01:00
Improve Scheduler task with try-catch-finally. Jobs should be deleted from db on error to prevent looping. Also errors should be logged
This commit is contained in:
parent
b3b516d0ad
commit
c834816e19
@ -15,6 +15,7 @@ use DateTimeImmutable;
|
|||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Xentral\Components\Database\Database;
|
use Xentral\Components\Database\Database;
|
||||||
|
use Xentral\Components\Logger\Logger;
|
||||||
use Xentral\Modules\SubscriptionCycle\Service\SubscriptionCycleJobService;
|
use Xentral\Modules\SubscriptionCycle\Service\SubscriptionCycleJobService;
|
||||||
use Xentral\Modules\SubscriptionCycle\SubscriptionCycleModuleInterface;
|
use Xentral\Modules\SubscriptionCycle\SubscriptionCycleModuleInterface;
|
||||||
use Xentral\Modules\SubscriptionCycle\SubscriptionModuleInterface;
|
use Xentral\Modules\SubscriptionCycle\SubscriptionModuleInterface;
|
||||||
@ -58,6 +59,7 @@ final class SubscriptionCycleManualJobTask
|
|||||||
$this->taskMutexService->setMutex('rechnungslauf_manual');
|
$this->taskMutexService->setMutex('rechnungslauf_manual');
|
||||||
$jobs = $this->cycleJobService->listAll(100);
|
$jobs = $this->cycleJobService->listAll(100);
|
||||||
foreach ($jobs as $job) {
|
foreach ($jobs as $job) {
|
||||||
|
try {
|
||||||
switch ($job['document_type']) {
|
switch ($job['document_type']) {
|
||||||
case 'rechnung':
|
case 'rechnung':
|
||||||
$this->subscriptionModule->CreateInvoice((int)$job['address_id']);
|
$this->subscriptionModule->CreateInvoice((int)$job['address_id']);
|
||||||
@ -66,9 +68,16 @@ final class SubscriptionCycleManualJobTask
|
|||||||
$this->subscriptionModule->CreateOrder((int)$job['address_id']);
|
$this->subscriptionModule->CreateOrder((int)$job['address_id']);
|
||||||
break;
|
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']);
|
$this->cycleJobService->delete((int)$job['id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function cleanup(): void
|
public function cleanup(): void
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user