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

64 lines
2.2 KiB

2 years ago
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.Threading;
using Volo.Abp.Uow;
10 months ago
using Win_in.Sfs.Wms.DataExchange.Domain;
2 years ago
using Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent.Outgoing;
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent;
public class MesOutgoingBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
{
private readonly string Outgoing = "MES Outgoing";
private readonly IOptions<MesOptions> _options;
public MesOutgoingBackgroundWorker(
AbpAsyncTimer timer
, IOptions<MesOptions> options
, IServiceScopeFactory serviceScopeFactory
) : base(timer, serviceScopeFactory)
{
_options = options;
Timer.Period = options.Value.OutgoingOptions.PeriodSeconds * 1000; //default 10 minutes
}
[UnitOfWork]
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{
Logger.LogInformation($"Starting: Handling {Outgoing}");
10 months ago
var configManager = workerContext.ServiceProvider.GetRequiredService<IInterfaceConfigManager>();
var confitem = await configManager.GetInterfaceConfig("MES-OUT").ConfigureAwait(false);
if (confitem == null)
{
if (!_options.Value.OutgoingOptions.Active)
{
Logger.LogInformation($"{Outgoing} 已关闭没有执行!");
return;
}
}
else
2 years ago
{
10 months ago
if (!confitem.Active)
{
Logger.LogInformation($"{Outgoing} 已关闭没有执行!");
return;
}
2 years ago
}
Logger.LogInformation($"Write Issue");
var issueConvert = workerContext.ServiceProvider.GetRequiredService<IssuesConverter>();
var issueNoteList = await issueConvert.ConvertAsync().ConfigureAwait(false);
var issueWriter = workerContext.ServiceProvider.GetRequiredService<IssueNoteWriter>();
await issueWriter.WriteAsync(issueNoteList).ConfigureAwait(false);
Logger.LogInformation($"Completed: Handling {Outgoing}");
}
}