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.

89 lines
2.8 KiB
C#

using DS.Module.Core;
using DS.WMS.Core.Code.Entity;
3 months ago
using Hangfire;
using Hangfire.MySql;
3 months ago
namespace DS.WMS.JobService
{
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
private BackgroundJobServer _OpServer;
public Worker(ILogger<Worker> logger)
{
3 months ago
_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)
{
3 months ago
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);
3 months ago
Console.WriteLine("Hangfire Server started. Press any key to exit...");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex);
3 months ago
}
await Task.Delay(1000, stoppingToken);
}
3 months ago
}
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;
}
}
}