update
This commit is contained in:
@@ -13,6 +13,7 @@ public class PollingService
|
||||
|
||||
private System.Threading.Timer? _timer;
|
||||
private bool _isProcessing;
|
||||
private DateTime _pollStartedAt;
|
||||
private int _totalPrinted;
|
||||
private readonly object _lock = new();
|
||||
|
||||
@@ -61,13 +62,27 @@ public class PollingService
|
||||
{
|
||||
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;
|
||||
_pollStartedAt = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
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ń");
|
||||
|
||||
if (jobs.Count == 0)
|
||||
@@ -85,7 +100,7 @@ public class PollingService
|
||||
try
|
||||
{
|
||||
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");
|
||||
|
||||
if (labelBytes.Length == 0)
|
||||
@@ -101,7 +116,7 @@ public class PollingService
|
||||
|
||||
if (success)
|
||||
{
|
||||
await _apiClient.MarkCompleteAsync(job.Id);
|
||||
await _apiClient.MarkCompleteAsync(job.Id, cts.Token);
|
||||
printed++;
|
||||
_totalPrinted++;
|
||||
LogForm.Log($"Job {job.Id}: wydrukowano i oznaczono jako complete ✓");
|
||||
@@ -140,8 +155,9 @@ public class PollingService
|
||||
{
|
||||
_onError($"API niedostępne: {ex.Message}");
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
LogForm.Log("Timeout: poll anulowany przez CancellationToken");
|
||||
_onError("Timeout połączenia z API");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user