定时器执行
This commit is contained in:
46
src/WMS.Web.Domain/QuartzJob/InventoryQuartzJob.cs
Normal file
46
src/WMS.Web.Domain/QuartzJob/InventoryQuartzJob.cs
Normal 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}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user