定时器执行

This commit is contained in:
18942506660
2024-10-21 10:24:56 +08:00
parent c7134674e3
commit 2b56446765
4 changed files with 70 additions and 4 deletions

View File

@@ -0,0 +1,46 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Quartz;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using WMS.Web.Domain.IService;
namespace WMS.Web.Domain.QuartzJob
{
//成品即时库存
public class InventoryQuartzJob : IJob
{
private readonly ILogger<InventoryQuartzJob> _logger;
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly IProductInventoryService _productInventoryService;
public InventoryQuartzJob(ILogger<InventoryQuartzJob> logger,
IServiceScopeFactory serviceScopeFactory, IProductInventoryService productInventoryService)
{
this._logger = logger;
_serviceScopeFactory = serviceScopeFactory;
_productInventoryService = productInventoryService;
}
/// <summary>
/// 执行方法
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public async Task Execute(IJobExecutionContext context)
{
try
{
if (DateTime.Now.Hour < 8 || DateTime.Now.Hour > 20) return;
var result = await _productInventoryService.Refresh();
}
catch (Exception ex)
{
_logger.LogInformation($"同步成品即时库存:定时任务执行失败->{ex.Message}");
}
}
}
}