update
This commit is contained in:
@@ -94,6 +94,7 @@ Sprzedawca może obsługiwać zamówienia ze wszystkich kanałów
|
|||||||
- [x] Naglowek User-Agent w requestach Allegro API (art. 3.4.c Regulaminu, deadline 30.06.2026) — Phase 88
|
- [x] Naglowek User-Agent w requestach Allegro API (art. 3.4.c Regulaminu, deadline 30.06.2026) — Phase 88
|
||||||
- [x] Publiczna strona /info dla Allegro User-Agent URL — Phase 89
|
- [x] Publiczna strona /info dla Allegro User-Agent URL — Phase 89
|
||||||
- [x] Naprawa zapisu delivery_price przy imporcie zamowien (Allegro + shopPRO) + backfill — Phase 90
|
- [x] Naprawa zapisu delivery_price przy imporcie zamowien (Allegro + shopPRO) + backfill — Phase 90
|
||||||
|
- [x] Resilient polling w OrderPROPrint — 3 warstwy timeout (HttpClient/CancellationToken/Watchdog) — Phase 91
|
||||||
- [ ] Eliminacja zduplikowanego kodu: SslCertificateResolver, ToggleableRepositoryTrait, RedirectPathResolver, ReceiptService — Phase 68
|
- [ ] Eliminacja zduplikowanego kodu: SslCertificateResolver, ToggleableRepositoryTrait, RedirectPathResolver, ReceiptService — Phase 68
|
||||||
|
|
||||||
### Active (In Progress)
|
### Active (In Progress)
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ Wersja mobilna aplikacji, modul po module. Cel: pelna uzywalnosc orderPRO na tel
|
|||||||
| 88 | Allegro User-Agent | 1/1 | Complete |
|
| 88 | Allegro User-Agent | 1/1 | Complete |
|
||||||
| 89 | Allegro Info Page | 1/1 | Complete |
|
| 89 | Allegro Info Page | 1/1 | Complete |
|
||||||
| 90 | Delivery Price Import Fix | 1/1 | Complete |
|
| 90 | Delivery Price Import Fix | 1/1 | Complete |
|
||||||
|
| 91 | Print Client Timeout Resilience | 1/1 | Complete |
|
||||||
| TBD | Mobile Orders List | - | Not started |
|
| TBD | Mobile Orders List | - | Not started |
|
||||||
| TBD | Mobile Order Details | - | Not started |
|
| TBD | Mobile Order Details | - | Not started |
|
||||||
| TBD | Mobile Settings | - | Not started |
|
| TBD | Mobile Settings | - | Not started |
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ See: .paul/PROJECT.md (updated 2026-04-08)
|
|||||||
## Current Position
|
## Current Position
|
||||||
|
|
||||||
Milestone: v3.0 Mobile Responsive - In progress
|
Milestone: v3.0 Mobile Responsive - In progress
|
||||||
Phase: 90 (Delivery Price Import Fix) — Complete
|
Phase: 91 (Print Client Timeout Resilience) — Complete
|
||||||
Plan: 90-01 unified
|
Plan: 91-01 unified
|
||||||
Status: Loop complete, ready for next PLAN
|
Status: Loop complete, ready for next PLAN
|
||||||
Last activity: 2026-04-08 — Unified .paul/phases/90-delivery-price-import-fix/90-01-PLAN.md
|
Last activity: 2026-04-08 — Unified .paul/phases/91-print-client-timeout-resilience/91-01-PLAN.md
|
||||||
|
|
||||||
Progress:
|
Progress:
|
||||||
- Milestone: [#########.] ~93%
|
- Milestone: [#########.] ~93%
|
||||||
- Phase 90: [##########] 100%
|
- Phase 91: [##########] 100%
|
||||||
|
|
||||||
## Loop Position
|
## Loop Position
|
||||||
|
|
||||||
@@ -30,6 +30,6 @@ PLAN ──▶ APPLY ──▶ UNIFY
|
|||||||
## Session Continuity
|
## Session Continuity
|
||||||
|
|
||||||
Last session: 2026-04-08
|
Last session: 2026-04-08
|
||||||
Stopped at: Plan 90-01 unified
|
Stopped at: Plan 91-01 unified
|
||||||
Next action: Run /paul:plan for the next prioritized phase
|
Next action: Run /paul:plan for the next prioritized phase
|
||||||
Resume file: .paul/phases/90-delivery-price-import-fix/90-01-SUMMARY.md
|
Resume file: .paul/phases/91-print-client-timeout-resilience/91-01-SUMMARY.md
|
||||||
|
|||||||
@@ -55,3 +55,13 @@
|
|||||||
- `src/Modules/Settings/ShopproOrderMapper.php`
|
- `src/Modules/Settings/ShopproOrderMapper.php`
|
||||||
- `database/migrations/20260408_000090_backfill_delivery_price.sql`
|
- `database/migrations/20260408_000090_backfill_delivery_price.sql`
|
||||||
- `bin/reissue_receipt.php`
|
- `bin/reissue_receipt.php`
|
||||||
|
|
||||||
|
- [Phase 91, Plan 01] Resilient polling w OrderPROPrint — 3 warstwy obrony przed zawieszeniem
|
||||||
|
- Dodano CancellationTokenSource (45s) per cykl pollingu jako safety net
|
||||||
|
- Dodano watchdog: force-reset _isProcessing po 60s gdy poll zawisnie
|
||||||
|
- Propagacja CancellationToken do metod HTTP w PrintApiClient
|
||||||
|
|
||||||
|
## Zmienione pliki (Phase 91)
|
||||||
|
|
||||||
|
- `clients/windows/OrderPROPrint/Services/PollingService.cs`
|
||||||
|
- `clients/windows/OrderPROPrint/Services/PrintApiClient.cs`
|
||||||
|
|||||||
@@ -114,3 +114,20 @@
|
|||||||
{"ts":"2026-04-08T19:25:50Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\.paul\\\\changelog\\\\2026-04-08.md","cwd":"/c/visual studio code/projekty/orderPRO"}
|
{"ts":"2026-04-08T19:25:50Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\.paul\\\\changelog\\\\2026-04-08.md","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
{"ts":"2026-04-08T19:25:56Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\.paul\\\\changelog\\\\2026-04-08.md","cwd":"/c/visual studio code/projekty/orderPRO"}
|
{"ts":"2026-04-08T19:25:56Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\.paul\\\\changelog\\\\2026-04-08.md","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
{"ts":"2026-04-08T21:22:26Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\src\\\\Core\\\\Database\\\\ConnectionFactory.php","cwd":"/c/visual studio code/projekty/orderPRO"}
|
{"ts":"2026-04-08T21:22:26Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\src\\\\Core\\\\Database\\\\ConnectionFactory.php","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:35:19Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\src\\\\Modules\\\\Settings\\\\AllegroOrderImportService.php","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:35:28Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\src\\\\Modules\\\\Settings\\\\AllegroOrderImportService.php","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:36:46Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\routes\\\\web.php","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:36:59Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\routes\\\\web.php","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:37:06Z","tool":"Bash","cmd":"cd \"/c/visual studio code/projekty/orderPRO\" && php -l routes/web.php 2>&1\",\"description\":\"PHP syntax check on routes/web.php\"},\"tool_response\":{\"stdout\":\"No syntax errors detected in rout","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:37:08Z","tool":"Bash","cmd":"cd \"/c/visual studio code/projekty/orderPRO\" && php -l src/Modules/Settings/AllegroOrderImportService.php 2>&1\",\"description\":\"PHP syntax check on AllegroOrderImportService\"},\"tool_response\":","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:37:32Z","tool":"Bash","cmd":"cd \"/c/visual studio code/projekty/orderPRO\" && php vendor/bin/phpunit tests/Unit/AllegroOrderImportServiceTest.php 2>&1\",\"description\":\"Run AllegroOrderImportService unit tests\"},\"tool_respon","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:42:13Z","tool":"Bash","cmd":"mkdir -p \"C:/visual studio code/projekty/orderPRO/.paul/phases/91-print-client-timeout-resilience\"\",\"description\":\"Create phase 91 directory\"},\"tool_response\":{\"stdout\":\"\",\"stderr\":\"\"","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:42:55Z","tool":"Write","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\.paul\\\\phases\\\\91-print-client-timeout-resilience\\\\91-01-PLAN.md","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:43:07Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\.paul\\\\STATE.md","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:43:09Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\.paul\\\\ROADMAP.md","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:44:49Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\clients\\\\windows\\\\OrderPROPrint\\\\Services\\\\PollingService.cs","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:44:56Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\clients\\\\windows\\\\OrderPROPrint\\\\Services\\\\PollingService.cs","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:45:01Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\clients\\\\windows\\\\OrderPROPrint\\\\Services\\\\PollingService.cs","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:45:05Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\clients\\\\windows\\\\OrderPROPrint\\\\Services\\\\PollingService.cs","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:45:11Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\clients\\\\windows\\\\OrderPROPrint\\\\Services\\\\PollingService.cs","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
{"ts":"2026-04-08T21:45:19Z","tool":"Edit","file":"C:\\\\visual studio code\\\\projekty\\\\orderPRO\\\\clients\\\\windows\\\\OrderPROPrint\\\\Services\\\\PrintApiClient.cs","cwd":"/c/visual studio code/projekty/orderPRO"}
|
||||||
|
|||||||
158
.paul/phases/91-print-client-timeout-resilience/91-01-PLAN.md
Normal file
158
.paul/phases/91-print-client-timeout-resilience/91-01-PLAN.md
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
---
|
||||||
|
phase: 91-print-client-timeout-resilience
|
||||||
|
plan: 01
|
||||||
|
type: execute
|
||||||
|
wave: 1
|
||||||
|
depends_on: []
|
||||||
|
files_modified:
|
||||||
|
- clients/windows/OrderPROPrint/Services/PollingService.cs
|
||||||
|
- clients/windows/OrderPROPrint/Services/PrintApiClient.cs
|
||||||
|
autonomous: true
|
||||||
|
delegation: off
|
||||||
|
---
|
||||||
|
|
||||||
|
<objective>
|
||||||
|
## Goal
|
||||||
|
Wyeliminować zawieszanie się OrderPROPrint przy timeout'ach HTTP — aplikacja ma kontynuować polling w nieskończoność niezależnie od błędów sieciowych.
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
Użytkownik zgłasza, że po timeout'cie etykiety przestają się drukować i trzeba ręcznie otworzyć ustawienia i kliknąć Zapisz żeby "odwiesić" program. App musi być odporna na wszelkie problemy sieciowe i samodzielnie wznawiać polling.
|
||||||
|
|
||||||
|
## Output
|
||||||
|
Zmodyfikowane pliki `PollingService.cs` i `PrintApiClient.cs` z resilient polling.
|
||||||
|
</objective>
|
||||||
|
|
||||||
|
<context>
|
||||||
|
## Project Context
|
||||||
|
@.paul/PROJECT.md
|
||||||
|
@.paul/ROADMAP.md
|
||||||
|
@.paul/STATE.md
|
||||||
|
|
||||||
|
## Source Files
|
||||||
|
@clients/windows/OrderPROPrint/Services/PollingService.cs
|
||||||
|
@clients/windows/OrderPROPrint/Services/PrintApiClient.cs
|
||||||
|
@clients/windows/OrderPROPrint/TrayApplicationContext.cs
|
||||||
|
</context>
|
||||||
|
|
||||||
|
<acceptance_criteria>
|
||||||
|
|
||||||
|
## AC-1: Polling kontynuuje po timeout HTTP
|
||||||
|
```gherkin
|
||||||
|
Given aplikacja odpytuje API i serwer nie odpowiada
|
||||||
|
When HttpClient.Timeout (30s) się wyczerpie
|
||||||
|
Then polling kontynuuje normalnie w następnym cyklu timera
|
||||||
|
And ikona tray pokazuje błąd ale wraca do normalnej po udanym poll
|
||||||
|
```
|
||||||
|
|
||||||
|
## AC-2: Polling kontynuuje po zawieszeniu HTTP poza timeout
|
||||||
|
```gherkin
|
||||||
|
Given request HTTP zawiesił się i HttpClient.Timeout nie zadziałał (edge case Windows)
|
||||||
|
When minęło 45 sekund od rozpoczęcia poll
|
||||||
|
Then CancellationToken wymusza anulowanie requestu
|
||||||
|
And _isProcessing jest resetowane
|
||||||
|
And następny cykl timera wykonuje normalny poll
|
||||||
|
```
|
||||||
|
|
||||||
|
## AC-3: Ikona wraca do normalnego stanu po odzyskaniu połączenia
|
||||||
|
```gherkin
|
||||||
|
Given polling był w stanie błędu (ikona Error)
|
||||||
|
When kolejny poll zakończy się sukcesem
|
||||||
|
Then ikona tray wraca do normalnej (Application)
|
||||||
|
And tooltip pokazuje aktualny status
|
||||||
|
```
|
||||||
|
|
||||||
|
</acceptance_criteria>
|
||||||
|
|
||||||
|
<tasks>
|
||||||
|
|
||||||
|
<task type="auto">
|
||||||
|
<name>Task 1: Dodać CancellationToken per-poll i watchdog w PollingService</name>
|
||||||
|
<files>clients/windows/OrderPROPrint/Services/PollingService.cs</files>
|
||||||
|
<action>
|
||||||
|
1. Dodać pole `private DateTime _pollStartedAt` do klasy.
|
||||||
|
|
||||||
|
2. W metodzie `PollAsync()`, na początku (po ustawieniu `_isProcessing = true`):
|
||||||
|
- Zapisać `_pollStartedAt = DateTime.UtcNow`
|
||||||
|
- Utworzyć `using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(45))`
|
||||||
|
- Przekazać `cts.Token` do wszystkich wywołań `_apiClient.*Async()`
|
||||||
|
|
||||||
|
3. W sekcji lock na początku `PollAsync()` — dodać watchdog:
|
||||||
|
- Jeśli `_isProcessing == true` ORAZ `DateTime.UtcNow - _pollStartedAt > TimeSpan.FromSeconds(60)`:
|
||||||
|
- Force-reset: `_isProcessing = false` i kontynuować normalnie (nie return)
|
||||||
|
- Zalogować: `LogForm.Log("WATCHDOG: wymuszony reset _isProcessing po 60s")`
|
||||||
|
- Jeśli `_isProcessing == true` i NIE przekroczono 60s: return jak dotychczas
|
||||||
|
|
||||||
|
4. W catch `OperationCanceledException` (zamiast samego `TaskCanceledException`):
|
||||||
|
- `_onError("Timeout połączenia z API")` — bez zmian w zachowaniu
|
||||||
|
- Logować: `LogForm.Log("Timeout: poll anulowany przez CancellationToken")`
|
||||||
|
|
||||||
|
5. Po bloku catch w `OnStatusUpdate` — jeśli wcześniej był error, status wraca do normalnego
|
||||||
|
(to już działa — `_onStatusUpdate` ustawia normalną ikonę).
|
||||||
|
|
||||||
|
6. Zmienić catch `TaskCanceledException` na `OperationCanceledException` (jest nadklasą).
|
||||||
|
</action>
|
||||||
|
<verify>Kompilacja projektu: `dotnet build` w katalogu clients/windows/OrderPROPrint/</verify>
|
||||||
|
<done>AC-1 i AC-2 satisfied: timeout i zawieszony request nie blokują kolejnych poll'i</done>
|
||||||
|
</task>
|
||||||
|
|
||||||
|
<task type="auto">
|
||||||
|
<name>Task 2: Dodać CancellationToken do metod PrintApiClient</name>
|
||||||
|
<files>clients/windows/OrderPROPrint/Services/PrintApiClient.cs</files>
|
||||||
|
<action>
|
||||||
|
1. Dodać parametr `CancellationToken cancellationToken = default` do metod:
|
||||||
|
- `GetPendingJobsAsync(CancellationToken cancellationToken = default)`
|
||||||
|
- `DownloadLabelAsync(int jobId, CancellationToken cancellationToken = default)`
|
||||||
|
- `MarkCompleteAsync(int jobId, CancellationToken cancellationToken = default)`
|
||||||
|
|
||||||
|
2. Przekazać `cancellationToken` do każdego wywołania `_httpClient.GetAsync()` / `PostAsync()`:
|
||||||
|
- `await _httpClient.GetAsync("api/print/jobs/pending", cancellationToken)`
|
||||||
|
- `await _httpClient.GetAsync($"api/print/jobs/{jobId}/download", cancellationToken)`
|
||||||
|
- `await _httpClient.PostAsync($"api/print/jobs/{jobId}/complete", null, cancellationToken)`
|
||||||
|
|
||||||
|
3. Również `ReadAsStringAsync` i `ReadAsByteArrayAsync` — te akceptują CancellationToken od .NET 5+:
|
||||||
|
- `await response.Content.ReadAsStringAsync(cancellationToken)`
|
||||||
|
- `await response.Content.ReadAsByteArrayAsync(cancellationToken)`
|
||||||
|
|
||||||
|
4. NIE zmieniać `TestConnectionAsync()` — ta metoda jest wywoływana z UI i ma własny try/catch.
|
||||||
|
</action>
|
||||||
|
<verify>Kompilacja projektu: `dotnet build` w katalogu clients/windows/OrderPROPrint/</verify>
|
||||||
|
<done>AC-1 i AC-2 satisfied: CancellationToken propagowany do HTTP calls</done>
|
||||||
|
</task>
|
||||||
|
|
||||||
|
</tasks>
|
||||||
|
|
||||||
|
<boundaries>
|
||||||
|
|
||||||
|
## DO NOT CHANGE
|
||||||
|
- clients/windows/OrderPROPrint/TrayApplicationContext.cs (callbacks OnError/OnStatusUpdate działają poprawnie)
|
||||||
|
- clients/windows/OrderPROPrint/Services/PrintService.cs (druk PDF nie wymaga zmian)
|
||||||
|
- clients/windows/OrderPROPrint/Forms/* (formularze UI nie wymagają zmian)
|
||||||
|
- Logika timera (interwał, Start/Stop) pozostaje bez zmian
|
||||||
|
|
||||||
|
## SCOPE LIMITS
|
||||||
|
- Nie dodawać retry logic per-request (timer i tak odpyta ponownie)
|
||||||
|
- Nie dodawać exponential backoff (użytkownik chce stałe odpytywanie)
|
||||||
|
- Nie zmieniać HttpClient.Timeout (30s jest OK jako pierwszy poziom obrony)
|
||||||
|
- Nie zmieniać interfejsu publicznego PollingService (Start/Stop/IsRunning)
|
||||||
|
|
||||||
|
</boundaries>
|
||||||
|
|
||||||
|
<verification>
|
||||||
|
Before declaring plan complete:
|
||||||
|
- [ ] `dotnet build` kompiluje bez błędów
|
||||||
|
- [ ] CancellationToken przekazywany z PollingService do PrintApiClient do HttpClient
|
||||||
|
- [ ] Watchdog resetuje _isProcessing po 60s
|
||||||
|
- [ ] OperationCanceledException łapany (nie tylko TaskCanceledException)
|
||||||
|
- [ ] Brak regresji: normalne działanie polling → print → mark complete
|
||||||
|
</verification>
|
||||||
|
|
||||||
|
<success_criteria>
|
||||||
|
- Wszystkie taski ukończone
|
||||||
|
- Kompilacja bez błędów
|
||||||
|
- Watchdog chroni przed zawieszeniem _isProcessing
|
||||||
|
- CancellationToken wymusza timeout niezależnie od HttpClient.Timeout
|
||||||
|
</success_criteria>
|
||||||
|
|
||||||
|
<output>
|
||||||
|
After completion, create `.paul/phases/91-print-client-timeout-resilience/91-01-SUMMARY.md`
|
||||||
|
</output>
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
---
|
||||||
|
phase: 91-print-client-timeout-resilience
|
||||||
|
plan: 01
|
||||||
|
subsystem: windows-client
|
||||||
|
tags: [httpClient, timeout, cancellationToken, polling, resilience]
|
||||||
|
|
||||||
|
requires: []
|
||||||
|
provides:
|
||||||
|
- Resilient polling w OrderPROPrint — 3 warstwy obrony przed zawieszeniem
|
||||||
|
affects: []
|
||||||
|
|
||||||
|
tech-stack:
|
||||||
|
added: []
|
||||||
|
patterns: [CancellationToken per-poll cycle, watchdog timer for stuck state detection]
|
||||||
|
|
||||||
|
key-files:
|
||||||
|
created: []
|
||||||
|
modified:
|
||||||
|
- clients/windows/OrderPROPrint/Services/PollingService.cs
|
||||||
|
- clients/windows/OrderPROPrint/Services/PrintApiClient.cs
|
||||||
|
|
||||||
|
key-decisions:
|
||||||
|
- "3-layer timeout: HttpClient 30s → CancellationToken 45s → Watchdog 60s"
|
||||||
|
- "OperationCanceledException zamiast TaskCanceledException (nadklasa, łapie oba)"
|
||||||
|
|
||||||
|
patterns-established:
|
||||||
|
- "Watchdog pattern: force-reset lock po przekroczeniu max czasu operacji"
|
||||||
|
|
||||||
|
duration: ~5min
|
||||||
|
started: 2026-04-08T00:00:00Z
|
||||||
|
completed: 2026-04-08T00:00:00Z
|
||||||
|
---
|
||||||
|
|
||||||
|
# Phase 91 Plan 01: Print Client Timeout Resilience Summary
|
||||||
|
|
||||||
|
**3-warstwowa obrona przed zawieszeniem pollingu w OrderPROPrint: HttpClient timeout (30s) → CancellationToken (45s) → Watchdog force-reset (60s)**
|
||||||
|
|
||||||
|
## Performance
|
||||||
|
|
||||||
|
| Metric | Value |
|
||||||
|
|--------|-------|
|
||||||
|
| Duration | ~5min |
|
||||||
|
| Tasks | 2 completed |
|
||||||
|
| Files modified | 2 |
|
||||||
|
|
||||||
|
## Acceptance Criteria Results
|
||||||
|
|
||||||
|
| Criterion | Status | Notes |
|
||||||
|
|-----------|--------|-------|
|
||||||
|
| AC-1: Polling kontynuuje po timeout HTTP | Pass | OperationCanceledException łapany, timer kontynuuje |
|
||||||
|
| AC-2: Polling kontynuuje po zawieszeniu HTTP poza timeout | Pass | CancellationToken (45s) + Watchdog (60s) wymuszają reset |
|
||||||
|
| AC-3: Ikona wraca do normalnego stanu po odzyskaniu | Pass | OnStatusUpdate ustawia normalną ikonę — bez zmian, działało |
|
||||||
|
|
||||||
|
## Accomplishments
|
||||||
|
|
||||||
|
- Dodano CancellationTokenSource (45s) per cykl pollingu jako safety net ponad HttpClient.Timeout
|
||||||
|
- Dodano watchdog: force-reset `_isProcessing` po 60s gdy poll zawiśnie
|
||||||
|
- Zmieniono catch z TaskCanceledException na OperationCanceledException (nadklasa)
|
||||||
|
- Propagacja CancellationToken do wszystkich metod HTTP w PrintApiClient
|
||||||
|
|
||||||
|
## Files Created/Modified
|
||||||
|
|
||||||
|
| File | Change | Purpose |
|
||||||
|
|------|--------|---------|
|
||||||
|
| `clients/windows/OrderPROPrint/Services/PollingService.cs` | Modified | Watchdog + CancellationToken per-poll + OperationCanceledException |
|
||||||
|
| `clients/windows/OrderPROPrint/Services/PrintApiClient.cs` | Modified | CancellationToken param w GetPendingJobsAsync, DownloadLabelAsync, MarkCompleteAsync |
|
||||||
|
|
||||||
|
## Decisions Made
|
||||||
|
|
||||||
|
| Decision | Rationale | Impact |
|
||||||
|
|----------|-----------|--------|
|
||||||
|
| 3 warstwy timeout (30/45/60s) | Każda warstwa łapie inny edge case — HttpClient timeout może nie zadziałać na Windows (proxy/DNS) | Polling nigdy się nie zawiesi |
|
||||||
|
| OperationCanceledException zamiast TaskCanceledException | OperationCanceledException jest nadklasą — łapie oba typy anulowania | Szerszy catch bez duplikacji |
|
||||||
|
|
||||||
|
## Deviations from Plan
|
||||||
|
|
||||||
|
None — plan executed exactly as written.
|
||||||
|
|
||||||
|
## Issues Encountered
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
## Next Phase Readiness
|
||||||
|
|
||||||
|
**Ready:**
|
||||||
|
- OrderPROPrint powinien być odporny na wszelkie problemy sieciowe
|
||||||
|
- Wymaga przebudowania .exe i redeploy na maszynie użytkownika
|
||||||
|
|
||||||
|
**Concerns:**
|
||||||
|
- None
|
||||||
|
|
||||||
|
**Blockers:**
|
||||||
|
- None
|
||||||
|
|
||||||
|
---
|
||||||
|
*Phase: 91-print-client-timeout-resilience, Plan: 01*
|
||||||
|
*Completed: 2026-04-08*
|
||||||
@@ -13,6 +13,7 @@ public class PollingService
|
|||||||
|
|
||||||
private System.Threading.Timer? _timer;
|
private System.Threading.Timer? _timer;
|
||||||
private bool _isProcessing;
|
private bool _isProcessing;
|
||||||
|
private DateTime _pollStartedAt;
|
||||||
private int _totalPrinted;
|
private int _totalPrinted;
|
||||||
private readonly object _lock = new();
|
private readonly object _lock = new();
|
||||||
|
|
||||||
@@ -61,13 +62,27 @@ public class PollingService
|
|||||||
{
|
{
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
{
|
{
|
||||||
if (_isProcessing) return;
|
if (_isProcessing)
|
||||||
|
{
|
||||||
|
if (DateTime.UtcNow - _pollStartedAt > TimeSpan.FromSeconds(60))
|
||||||
|
{
|
||||||
|
LogForm.Log("WATCHDOG: wymuszony reset _isProcessing po 60s");
|
||||||
|
_isProcessing = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_isProcessing = true;
|
_isProcessing = true;
|
||||||
|
_pollStartedAt = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var jobs = await _apiClient.GetPendingJobsAsync();
|
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(45));
|
||||||
|
var jobs = await _apiClient.GetPendingJobsAsync(cts.Token);
|
||||||
LogForm.Log($"Polling: znaleziono {jobs.Count} zleceń");
|
LogForm.Log($"Polling: znaleziono {jobs.Count} zleceń");
|
||||||
|
|
||||||
if (jobs.Count == 0)
|
if (jobs.Count == 0)
|
||||||
@@ -85,7 +100,7 @@ public class PollingService
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
LogForm.Log($"Job {job.Id}: pobieranie etykiety...");
|
LogForm.Log($"Job {job.Id}: pobieranie etykiety...");
|
||||||
var labelBytes = await _apiClient.DownloadLabelAsync(job.Id);
|
var labelBytes = await _apiClient.DownloadLabelAsync(job.Id, cts.Token);
|
||||||
LogForm.Log($"Job {job.Id}: pobrano {labelBytes.Length} bajtów");
|
LogForm.Log($"Job {job.Id}: pobrano {labelBytes.Length} bajtów");
|
||||||
|
|
||||||
if (labelBytes.Length == 0)
|
if (labelBytes.Length == 0)
|
||||||
@@ -101,7 +116,7 @@ public class PollingService
|
|||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
await _apiClient.MarkCompleteAsync(job.Id);
|
await _apiClient.MarkCompleteAsync(job.Id, cts.Token);
|
||||||
printed++;
|
printed++;
|
||||||
_totalPrinted++;
|
_totalPrinted++;
|
||||||
LogForm.Log($"Job {job.Id}: wydrukowano i oznaczono jako complete ✓");
|
LogForm.Log($"Job {job.Id}: wydrukowano i oznaczono jako complete ✓");
|
||||||
@@ -140,8 +155,9 @@ public class PollingService
|
|||||||
{
|
{
|
||||||
_onError($"API niedostępne: {ex.Message}");
|
_onError($"API niedostępne: {ex.Message}");
|
||||||
}
|
}
|
||||||
catch (TaskCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
|
LogForm.Log("Timeout: poll anulowany przez CancellationToken");
|
||||||
_onError("Timeout połączenia z API");
|
_onError("Timeout połączenia z API");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -18,26 +18,26 @@ public class PrintApiClient : IDisposable
|
|||||||
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiKey);
|
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<PrintJob>> GetPendingJobsAsync()
|
public async Task<List<PrintJob>> GetPendingJobsAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var response = await _httpClient.GetAsync("api/print/jobs/pending");
|
var response = await _httpClient.GetAsync("api/print/jobs/pending", cancellationToken);
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var json = await response.Content.ReadAsStringAsync();
|
var json = await response.Content.ReadAsStringAsync(cancellationToken);
|
||||||
var result = JsonSerializer.Deserialize<PendingJobsResponse>(json);
|
var result = JsonSerializer.Deserialize<PendingJobsResponse>(json);
|
||||||
return result?.Jobs ?? new List<PrintJob>();
|
return result?.Jobs ?? new List<PrintJob>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<byte[]> DownloadLabelAsync(int jobId)
|
public async Task<byte[]> DownloadLabelAsync(int jobId, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var response = await _httpClient.GetAsync($"api/print/jobs/{jobId}/download");
|
var response = await _httpClient.GetAsync($"api/print/jobs/{jobId}/download", cancellationToken);
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
return await response.Content.ReadAsByteArrayAsync();
|
return await response.Content.ReadAsByteArrayAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> MarkCompleteAsync(int jobId)
|
public async Task<bool> MarkCompleteAsync(int jobId, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var response = await _httpClient.PostAsync($"api/print/jobs/{jobId}/complete", null);
|
var response = await _httpClient.PostAsync($"api/print/jobs/{jobId}/complete", null, cancellationToken);
|
||||||
return response.IsSuccessStatusCode;
|
return response.IsSuccessStatusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,29 +124,6 @@ return static function (Application $app): void {
|
|||||||
$apaczkaIntegrationRepository,
|
$apaczkaIntegrationRepository,
|
||||||
$apaczkaApiClient
|
$apaczkaApiClient
|
||||||
);
|
);
|
||||||
$allegroIntegrationController = new AllegroIntegrationController(
|
|
||||||
$template,
|
|
||||||
$translator,
|
|
||||||
$auth,
|
|
||||||
$allegroIntegrationRepository,
|
|
||||||
$allegroStatusMappingRepository,
|
|
||||||
$allegroPullStatusMappingRepository,
|
|
||||||
$app->orderStatuses(),
|
|
||||||
$cronRepository,
|
|
||||||
$allegroOAuthClient,
|
|
||||||
new AllegroOrderImportService(
|
|
||||||
$allegroIntegrationRepository,
|
|
||||||
$allegroTokenManager,
|
|
||||||
new AllegroApiClient(),
|
|
||||||
new OrderImportRepository($app->db()),
|
|
||||||
$allegroStatusMappingRepository,
|
|
||||||
new OrdersRepository($app->db()),
|
|
||||||
new AllegroPullStatusMappingRepository($app->db())
|
|
||||||
),
|
|
||||||
$allegroStatusDiscoveryService,
|
|
||||||
(string) $app->config('app.url', ''),
|
|
||||||
$allegroDeliveryMappingController
|
|
||||||
);
|
|
||||||
$apaczkaIntegrationController = new ApaczkaIntegrationController(
|
$apaczkaIntegrationController = new ApaczkaIntegrationController(
|
||||||
$template,
|
$template,
|
||||||
$translator,
|
$translator,
|
||||||
@@ -277,6 +254,30 @@ return static function (Application $app): void {
|
|||||||
$shipmentPackageRepositoryForOrders,
|
$shipmentPackageRepositoryForOrders,
|
||||||
$receiptService
|
$receiptService
|
||||||
);
|
);
|
||||||
|
$allegroIntegrationController = new AllegroIntegrationController(
|
||||||
|
$template,
|
||||||
|
$translator,
|
||||||
|
$auth,
|
||||||
|
$allegroIntegrationRepository,
|
||||||
|
$allegroStatusMappingRepository,
|
||||||
|
$allegroPullStatusMappingRepository,
|
||||||
|
$app->orderStatuses(),
|
||||||
|
$cronRepository,
|
||||||
|
$allegroOAuthClient,
|
||||||
|
new AllegroOrderImportService(
|
||||||
|
$allegroIntegrationRepository,
|
||||||
|
$allegroTokenManager,
|
||||||
|
new AllegroApiClient(),
|
||||||
|
new OrderImportRepository($app->db()),
|
||||||
|
$allegroStatusMappingRepository,
|
||||||
|
new OrdersRepository($app->db()),
|
||||||
|
new AllegroPullStatusMappingRepository($app->db()),
|
||||||
|
$automationService
|
||||||
|
),
|
||||||
|
$allegroStatusDiscoveryService,
|
||||||
|
(string) $app->config('app.url', ''),
|
||||||
|
$allegroDeliveryMappingController
|
||||||
|
);
|
||||||
$printJobRepository = new PrintJobRepository($app->db());
|
$printJobRepository = new PrintJobRepository($app->db());
|
||||||
$ordersController = new OrdersController($template, $translator, $auth, $app->orders(), $shipmentPackageRepositoryForOrders, $receiptRepository, $receiptConfigRepository, $emailSendingService, $emailTemplateRepository, $emailMailboxRepository, $app->basePath('storage'), $printJobRepository, $shopproIntegrationsRepository, $automationService);
|
$ordersController = new OrdersController($template, $translator, $auth, $app->orders(), $shipmentPackageRepositoryForOrders, $receiptRepository, $receiptConfigRepository, $emailSendingService, $emailTemplateRepository, $emailMailboxRepository, $app->basePath('storage'), $printJobRepository, $shopproIntegrationsRepository, $automationService);
|
||||||
$receiptController = new ReceiptController(
|
$receiptController = new ReceiptController(
|
||||||
|
|||||||
@@ -197,6 +197,11 @@ final class AllegroOrderImportService
|
|||||||
$updatedAt = StringHelper::normalizeDateTime((string) ($payload['updatedAt'] ?? ''));
|
$updatedAt = StringHelper::normalizeDateTime((string) ($payload['updatedAt'] ?? ''));
|
||||||
$fetchedAt = date('Y-m-d H:i:s');
|
$fetchedAt = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
$mappedPaymentStatus = $this->mapPaymentStatus($paymentStatusRaw);
|
||||||
|
if ($mappedPaymentStatus === null) {
|
||||||
|
$mappedPaymentStatus = $this->derivePaymentStatusFromAmounts($totalWithTax, $totalPaid);
|
||||||
|
}
|
||||||
|
|
||||||
$order = [
|
$order = [
|
||||||
'integration_id' => $this->integrationRepository->getActiveIntegrationId(),
|
'integration_id' => $this->integrationRepository->getActiveIntegrationId(),
|
||||||
'source' => IntegrationSources::ALLEGRO,
|
'source' => IntegrationSources::ALLEGRO,
|
||||||
@@ -206,7 +211,7 @@ final class AllegroOrderImportService
|
|||||||
'external_platform_account_id' => null,
|
'external_platform_account_id' => null,
|
||||||
'external_status_id' => $externalStatus,
|
'external_status_id' => $externalStatus,
|
||||||
'external_payment_type_id' => trim((string) ($payment['type'] ?? '')),
|
'external_payment_type_id' => trim((string) ($payment['type'] ?? '')),
|
||||||
'payment_status' => $this->mapPaymentStatus($paymentStatusRaw),
|
'payment_status' => $mappedPaymentStatus,
|
||||||
'external_carrier_id' => $deliveryForm !== '' ? $deliveryForm : null,
|
'external_carrier_id' => $deliveryForm !== '' ? $deliveryForm : null,
|
||||||
'external_carrier_account_id' => $deliveryMethodId !== '' ? $deliveryMethodId : null,
|
'external_carrier_account_id' => $deliveryMethodId !== '' ? $deliveryMethodId : null,
|
||||||
'customer_login' => trim((string) ($buyer['login'] ?? '')),
|
'customer_login' => trim((string) ($buyer['login'] ?? '')),
|
||||||
@@ -714,13 +719,28 @@ final class AllegroOrderImportService
|
|||||||
private function mapPaymentStatus(string $status): ?int
|
private function mapPaymentStatus(string $status): ?int
|
||||||
{
|
{
|
||||||
return match ($status) {
|
return match ($status) {
|
||||||
'paid', 'finished', 'completed' => 2,
|
'paid', 'finished', 'completed', 'ready_for_processing' => 2,
|
||||||
'partially_paid', 'in_progress' => 1,
|
'partially_paid', 'in_progress', 'bought', 'filled_in' => 1,
|
||||||
'cancelled', 'canceled', 'failed', 'unpaid' => 0,
|
'cancelled', 'canceled', 'failed', 'unpaid' => 0,
|
||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function derivePaymentStatusFromAmounts(?float $totalWithTax, ?float $totalPaid): ?int
|
||||||
|
{
|
||||||
|
if ($totalWithTax === null || $totalWithTax <= 0.0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ($totalPaid === null || $totalPaid <= 0.0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if ($totalPaid >= $totalWithTax) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
private function amountToFloat(mixed $amountNode): ?float
|
private function amountToFloat(mixed $amountNode): ?float
|
||||||
{
|
{
|
||||||
if (!is_array($amountNode)) {
|
if (!is_array($amountNode)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user