job status reporting
This commit is contained in:
@@ -16,11 +16,12 @@ public class PrinterQueue
|
||||
private readonly IPrintService _printService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly PrintServer _printServer;
|
||||
private readonly IJobStatusReporter _statusReporter;
|
||||
|
||||
public bool IsProcessing { get; private set; }
|
||||
public int QueueLength => _queue.Count + _priorityQueue.Count;
|
||||
|
||||
public PrinterQueue(string printerIp, IPrintService printService, ILogger logger, PrintServer printServer)
|
||||
public PrinterQueue(string printerIp, IPrintService printService, ILogger logger, PrintServer printServer, IJobStatusReporter statusReporter)
|
||||
{
|
||||
PrinterIp = printerIp;
|
||||
_queue = new ConcurrentQueue<PrintJob>();
|
||||
@@ -30,12 +31,14 @@ public class PrinterQueue
|
||||
_printService = printService;
|
||||
_logger = logger;
|
||||
_printServer = printServer;
|
||||
_statusReporter = statusReporter;
|
||||
}
|
||||
|
||||
public void Enqueue(PrintJob job)
|
||||
{
|
||||
_queue.Enqueue(job);
|
||||
_signal.Release(); // Signal that there's work to do
|
||||
_statusReporter.ReportStatusAsync(job, PrintJobStatus.Received).GetAwaiter().GetResult();
|
||||
_logger.LogInformation("Job queued for printer {PrinterId}. Queue length: {QueueLength}", PrinterIp, QueueLength);
|
||||
}
|
||||
|
||||
@@ -83,6 +86,7 @@ public class PrinterQueue
|
||||
if (result.ErrorType == PrintErrorType.ConversionError)
|
||||
{
|
||||
_logger.LogWarning("Job failed due to conversion error, not re-queuing");
|
||||
await _statusReporter.ReportStatusAsync(job, PrintJobStatus.Failed);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -96,12 +100,13 @@ public class PrinterQueue
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("Job completed successfully on printer {PrinterId}", PrinterIp);
|
||||
await _statusReporter.ReportStatusAsync(job, PrintJobStatus.Completed);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error processing job");
|
||||
// Handle exception (retry, log, etc.)
|
||||
await _statusReporter.ReportStatusAsync(job, PrintJobStatus.Failed);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user