|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using Hangfire;
|
|
|
|
|
using Hangfire.MySql;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.JobService
|
|
|
|
|
{
|
|
|
|
|
public class Worker : BackgroundService
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<Worker> _logger;
|
|
|
|
|
private BackgroundJobServer _server;
|
|
|
|
|
public Worker(ILogger<Worker> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|