job status reporting
This commit is contained in:
@@ -11,6 +11,7 @@ using Inspectron.Epson.PrintServer.Printers;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils;
|
||||
using Inspectron.Epson.PrintServer.PrintServices;
|
||||
using EpsonPrintService;
|
||||
using Inspectron.Epson.PrintServer.JobStatusReporters;
|
||||
using Inspectron.Epson.Queue;
|
||||
|
||||
StandardKernel kernel = new StandardKernel();
|
||||
@@ -67,7 +68,7 @@ kernel.Bind<ILogger>().ToMethod(ctx =>
|
||||
kernel.Bind<IWrapperPrinterFactory>().To<PrinterWrapperFactory>().InSingletonScope();
|
||||
kernel.Bind<IPrinterConfigurationSource>().To<FixedConfigurationSource>();
|
||||
kernel.Bind<IReceiptConverterFactory>().To<ReceiptConverterFactory>().InSingletonScope();
|
||||
kernel.Bind<IJobStatusReporter>().To<NullJobStatusReporter>();
|
||||
kernel.Bind<IJobStatusReporter>().To<JamesStatusReporter>();
|
||||
kernel.Bind<PrintServer>().ToSelf().InSingletonScope();
|
||||
kernel.Bind<IDiscoveredPrintersReceiver>().To<JamesDiscoveredPrintersReceiver>().InSingletonScope();
|
||||
kernel.Bind<PrinterDiscoveryBackgroundTask>().ToSelf().InSingletonScope();
|
||||
|
||||
@@ -1 +1 @@
|
||||
aHR0cHM6Ly9hcGkuZGV2Lmdhc3Ryb2phbWVzLmNoOzY4ODc1MjY2MTcxMjgxN2RlMjcxNTlmMjtGTEVEL1phQ2F5a0NrdEpCOHZzN1lqVFNyaStleGdKVWIva21WWk1lUHBNPQ==
|
||||
aHR0cHM6Ly9hcGkuZGV2Lmdhc3Ryb2phbWVzLmNoOzYzZTM3Mjk1YmQ2ZjI2ZGJkMzYxNjRjMDs3VnBaQXNTKzcwTEdKTXFRQi9nNWlkMlZIZ3FybmR4RUpXeDVLYXF2YThzPQ==
|
||||
@@ -100,6 +100,7 @@ public class SignalRPrintJobSource: IPrintJobSource
|
||||
_logger.LogInformation("Received print job for working area: {PrintJob}", JsonSerializer.Serialize(args));
|
||||
_printJobChannel.Writer.TryWrite(new PrintJob
|
||||
{
|
||||
JobId = args.JobId,
|
||||
IP = args.PrinterIp,
|
||||
Document = args,
|
||||
});
|
||||
@@ -112,6 +113,9 @@ public class SignalRPrintJobSource: IPrintJobSource
|
||||
|
||||
public class PrintJobFromSignalR
|
||||
{
|
||||
[JsonPropertyName("jobId")]
|
||||
public string JobId { get; set; }
|
||||
|
||||
[JsonPropertyName("printerIp")]
|
||||
public string PrinterIp { get; set; }
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using Inspectron.Epson.PrintServer.ConfigurationSources;
|
||||
using Inspectron.Epson.Queue;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace Inspectron.Epson.PrintServer.JobStatusReporters;
|
||||
|
||||
public class JamesStatusReporter : IJobStatusReporter
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly EpsonPrintServiceConfiguration _configuration;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public JamesStatusReporter(HttpClient httpClient, EpsonPrintServiceConfiguration configuration, ILogger logger)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_configuration = configuration;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task ReportStatusAsync(PrintJob job, PrintJobStatus status)
|
||||
{
|
||||
try
|
||||
{
|
||||
var url = $"{_configuration.ApiUrl?.TrimEnd('/')}/api/printerServer/job-update";
|
||||
using var request = new HttpRequestMessage(HttpMethod.Post, url);
|
||||
request.Headers.Add("X-Printer-Server-Key", _configuration.ApiKey);
|
||||
request.Content = JsonContent.Create(new
|
||||
{
|
||||
jobId = job.JobId,
|
||||
status = (int)status
|
||||
});
|
||||
|
||||
var response = await _httpClient.SendAsync(request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to report status {Status} for job {JobId}", status, job.JobId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace Inspectron.Epson.Queue;
|
||||
|
||||
public class PrintJob
|
||||
{
|
||||
// todo: change to ip address
|
||||
public string JobId { get; set; }
|
||||
public string IP { get; set; }
|
||||
public PrintJobFromSignalR Document { get; set; }
|
||||
public DateTime QueuedAt { get; set; }
|
||||
|
||||
@@ -2,7 +2,7 @@ namespace Inspectron.Epson.Queue;
|
||||
|
||||
public enum PrintJobStatus
|
||||
{
|
||||
Received,
|
||||
Completed,
|
||||
Failed
|
||||
Received=1,
|
||||
Completed=2,
|
||||
Failed=3
|
||||
}
|
||||
@@ -106,6 +106,7 @@ public class PrintServer
|
||||
else
|
||||
{
|
||||
_logger.LogWarning( $"Printer {printerIp} not found. Job cannot be submitted.");
|
||||
_statusReporter.ReportStatusAsync(job, PrintJobStatus.Failed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user