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.
42 lines
1.7 KiB
42 lines
1.7 KiB
2 years ago
|
using System.Collections.Generic;
|
||
|
using System.Threading.Tasks;
|
||
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
using Microsoft.Extensions.Options;
|
||
|
using Volo.Abp.BackgroundWorkers;
|
||
|
using Volo.Abp.Threading;
|
||
|
using Win_in.Sfs.Store.Application.Contracts;
|
||
|
using Win_in.Sfs.Wms.DataExchange.Domain;
|
||
|
using IObjectMapper = Volo.Abp.ObjectMapping.IObjectMapper;
|
||
|
|
||
|
namespace Win_in.Sfs.Wms.DataExchange.Agent;
|
||
|
|
||
|
public class OutgoingFromWmsWorker : AsyncPeriodicBackgroundWorkerBase
|
||
|
{
|
||
|
private readonly OutgoingOptions _options;
|
||
|
|
||
|
public OutgoingFromWmsWorker(
|
||
|
AbpAsyncTimer timer,
|
||
|
IOptions<DataExchangeOptions> options,
|
||
|
IServiceScopeFactory serviceScopeFactory
|
||
|
) : base(timer, serviceScopeFactory)
|
||
|
{
|
||
|
_options = options.Value.OutgoingOptions;
|
||
|
Timer.Period = options.Value.OutgoingOptions.PeriodSeconds * 1000; //default 5 minutes
|
||
|
}
|
||
|
|
||
|
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
|
||
|
{
|
||
|
//Resolve dependencies
|
||
|
var exchangeDataAppService = workerContext.ServiceProvider.GetRequiredService<IExchangeDataAppService>();
|
||
|
var objectMapper = workerContext.ServiceProvider.GetRequiredService<IObjectMapper>();
|
||
|
var outgoingFromWmsManager = workerContext.ServiceProvider.GetRequiredService<OutgoingFromWmsManager>();
|
||
|
|
||
|
//Do the work
|
||
|
var batchSize = _options.BatchSize;
|
||
|
var exchangeDataList = await exchangeDataAppService.GetToBeProcessedListAsync(batchSize).ConfigureAwait(false);
|
||
|
var outgoingFromWmsList = objectMapper.Map<List<ExchangeDataDTO>, List<OutgoingFromWms>>(exchangeDataList);
|
||
|
await outgoingFromWmsManager.CreateManyAsync(outgoingFromWmsList).ConfigureAwait(false);
|
||
|
|
||
|
}
|
||
|
}
|