You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.9 KiB
C#

using DS.Module.Core;
using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.HangfireJob.Interface;
using Hangfire;
using Hangfire.MySql;
namespace DS.WMS.JobService
{
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
private BackgroundJobServer _OpServer;
public Worker(ILogger<Worker> logger)
{
_logger = logger;
}
public override async Task StartAsync(CancellationToken stoppingToken)
{
try
{
while (!stoppingToken.IsCancellationRequested)
{
_OpServer = new BackgroundJobServer(new BackgroundJobServerOptions
{
SchedulePollingInterval = TimeSpan.FromMinutes(1),
ServerName = "OpWorkService",
Queues = new[] { "op" }
});
await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken);
}
}
catch (OperationCanceledException ex)
{
Console.WriteLine(ex.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
//Environment.Exit(1);
}
}
//protected override async Task StopAsync(CancellationToken stoppingToken)
//{
//}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
//var options = new BackgroundJobServerOptions
//{
// SchedulePollingInterval = TimeSpan.FromMinutes(1),
// ServerName = "WorkService",
// Queues = new[] { "op", "task" }
//};
while (!stoppingToken.IsCancellationRequested)
{
try
{
//_server = new BackgroundJobServer(options);
//_server = new BackgroundJobServer(new BackgroundJobServerOptions
//{
// SchedulePollingInterval = TimeSpan.FromMinutes(1),
// ServerName = "WorkService",
// Queues = new[] { "op", "task" }
//});
//_server = new BackgroundJobServer();
await DoWork(stoppingToken);
Console.WriteLine("Hangfire Server started. Press any key to exit...");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
await Task.Delay(1000, stoppingToken);
}
}
private async Task DoWork(CancellationToken cancellationToken)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD>
await Task.CompletedTask;
}
}
}