46 lines
1.9 KiB
C#
46 lines
1.9 KiB
C#
using LCU.Api.Internal.MaidBotLib.Models;
|
|
using LCU.Library.Internal.Exceptions;
|
|
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services.Dayforce;
|
|
using MassTransit;
|
|
|
|
namespace LCU.API.Internal.Operations.IncentiveApi.Consumers;
|
|
|
|
public class DayforceSyncProcessConsumer : IConsumer<DayforceProcessRequest>
|
|
{
|
|
private readonly IServiceScopeFactory _scopeFactory;
|
|
|
|
public DayforceSyncProcessConsumer(IServiceScopeFactory scopeFactory)
|
|
{
|
|
_scopeFactory = scopeFactory;
|
|
}
|
|
|
|
public async Task Consume(ConsumeContext<DayforceProcessRequest> context)
|
|
{
|
|
try
|
|
{
|
|
Log.Debug("Starting Dayforce Sync Process.");
|
|
using var scope = _scopeFactory.CreateScope();
|
|
await Task.Run(async () => await scope.ServiceProvider.GetRequiredService<IDayForceSyncService>().SyncDayForceUsers(context.Message));
|
|
Log.Debug("Finished Dayforce Sync Process.");
|
|
}
|
|
catch (ServiceException serviceException)
|
|
{
|
|
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
|
|
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
|
|
.Error(serviceException, $"Dayforce Sync Failure. " +
|
|
$"The Dayforce Sync Process Request is placed on LCU.IncentiveApi.DayforceSyncProcess_error.");
|
|
throw;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.ForContext(Enum.GetName(typeof(PropertyEnum), PropertyEnum.Group),
|
|
Enum.GetName(typeof(GroupEnum), GroupEnum.ITDevelopment))
|
|
.Fatal(exception, $"Dayforce Sync Failure. " +
|
|
$"The Dayforce Sync Failure Process Request is placed on LCU.IncentiveApi.DayforceSyncProcess_error.");
|
|
throw;
|
|
}
|
|
}
|
|
}
|