fix: Apilo email z danymi zamówienia + infinite retry co 30 min dla order jobów

- Email notyfikacji zawiera numer zamówienia, klienta, datę, kwotę
- Order joby (send_order, sync_payment, sync_status) ponawiane w nieskończoność co 30 min
- Rozróżnienie PONAWIANY vs TRWAŁY BŁĄD w emailu
- Cleanup stuck jobów po udanym wysłaniu zamówienia
- +2 testy infinite retry w CronJobRepositoryTest

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jacek
2026-03-19 11:23:02 +01:00
parent 4cda46d4bc
commit 72864d18ba
12 changed files with 476 additions and 27 deletions

View File

@@ -205,6 +205,7 @@ class CronJobRepositoryTest extends TestCase
{
// Job with attempts < max_attempts → reschedule with backoff
$this->mockDb->method('get')->willReturn([
'job_type' => 'price_history',
'max_attempts' => 10,
'attempts' => 2,
]);
@@ -228,6 +229,7 @@ class CronJobRepositoryTest extends TestCase
{
// Job with attempts >= max_attempts → permanent failure
$this->mockDb->method('get')->willReturn([
'job_type' => 'price_history',
'max_attempts' => 3,
'attempts' => 3,
]);
@@ -249,6 +251,7 @@ class CronJobRepositoryTest extends TestCase
public function testMarkFailedTruncatesErrorTo500Chars(): void
{
$this->mockDb->method('get')->willReturn([
'job_type' => 'price_history',
'max_attempts' => 10,
'attempts' => 1,
]);
@@ -268,6 +271,51 @@ class CronJobRepositoryTest extends TestCase
$this->repo->markFailed(1, $longError);
}
public function testMarkFailedApiloOrderJobNeverPermanentlyFails(): void
{
// apilo_send_order with max attempts reached → still pending (infinite retry)
$this->mockDb->method('get')->willReturn([
'job_type' => 'apilo_send_order',
'max_attempts' => 10,
'attempts' => 15,
]);
$this->mockDb->expects($this->once())
->method('update')
->with(
'pp_cron_jobs',
$this->callback(function ($data) {
return $data['status'] === 'pending'
&& isset($data['scheduled_at'])
&& isset($data['last_error']);
}),
['id' => 5]
);
$this->repo->markFailed(5, 'API timeout');
}
public function testMarkFailedApiloSyncPaymentInfiniteRetry(): void
{
$this->mockDb->method('get')->willReturn([
'job_type' => 'apilo_sync_payment',
'max_attempts' => 10,
'attempts' => 10,
]);
$this->mockDb->expects($this->once())
->method('update')
->with(
'pp_cron_jobs',
$this->callback(function ($data) {
return $data['status'] === 'pending';
}),
['id' => 6]
);
$this->repo->markFailed(6, 'Apilo unavailable');
}
// --- hasPendingJob ---
public function testHasPendingJobReturnsTrueWhenExists(): void