|
|
@ -1,5 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using DocumentFormat.OpenXml.Office2010.Drawing; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
@ -15,6 +17,39 @@ using Win_in.Sfs.Basedata.Domain.Shared; |
|
|
|
|
|
|
|
namespace Win_in.Sfs.Basedata.Application; |
|
|
|
|
|
|
|
|
|
|
|
public class TaskQueue |
|
|
|
{ |
|
|
|
private readonly List<TaskItem> _tasks = new List<TaskItem>(); |
|
|
|
|
|
|
|
public void Enqueue(string name, Action action) |
|
|
|
{ |
|
|
|
_tasks.Add(new TaskItem { Name = name, Action = action }); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task StartAsync() |
|
|
|
{ |
|
|
|
foreach (var task in _tasks) |
|
|
|
{ |
|
|
|
await Task.Run(task.Action).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
public class TaskItem |
|
|
|
{ |
|
|
|
public string Name { get; set; } |
|
|
|
public Action Action { get; set; } |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class CycleOptions |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
@ -24,7 +59,7 @@ public class CycleOptions |
|
|
|
|
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 提供缓存服务的类
|
|
|
|
/// 提供缓存服务的类(堵塞以后修改再用)
|
|
|
|
/// </summary>
|
|
|
|
public class CacheService:ISingletonDependency |
|
|
|
{ |
|
|
@ -41,32 +76,32 @@ public class CacheService:ISingletonDependency |
|
|
|
/// </summary>
|
|
|
|
private async Task BomsCycle() |
|
|
|
{ |
|
|
|
using var serviceScope = _serviceProvider.CreateScope(); |
|
|
|
var repository = serviceScope.ServiceProvider.GetRequiredService<IBomRepository>(); |
|
|
|
var reassigner = new Reassigner(DateTime.Now, new TimeSpan(0, 0, _options.Value.BomsCycle==0?600: _options.Value.BomsCycle)); |
|
|
|
await reassigner.RunAsync(async () => |
|
|
|
{ |
|
|
|
Cache.Boms.Clear(); |
|
|
|
Cache.Boms = await repository.GetListAsync().ConfigureAwait(false); |
|
|
|
|
|
|
|
}).ConfigureAwait(false); |
|
|
|
//Task.Run(async () =>
|
|
|
|
//{
|
|
|
|
var reassigner = new Reassigner(DateTime.Now, new TimeSpan(0, 0, _options.Value.BomsCycle == 0 ? 60 : _options.Value.BomsCycle)); |
|
|
|
await reassigner.RunAsync(async () => |
|
|
|
{ |
|
|
|
using var serviceScope = _serviceProvider.CreateScope(); |
|
|
|
var repository = serviceScope.ServiceProvider.GetRequiredService<IBomRepository>(); |
|
|
|
Cache.Boms.Clear(); |
|
|
|
Cache.Boms = await repository.GetListAsync().ConfigureAwait(false); |
|
|
|
|
|
|
|
}).ConfigureAwait(false); |
|
|
|
//});
|
|
|
|
; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 异步开始生命周期操作
|
|
|
|
/// 异步开始生命周期操作不能堵塞
|
|
|
|
/// </summary>
|
|
|
|
public async Task StartAsync() |
|
|
|
{ |
|
|
|
await BomsCycle().ConfigureAwait(false); |
|
|
|
} |
|
|
|
BomsCycle();//异步处理不能堵塞主任务
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 异步重置BOM(Bill of Materials)生命周期操作
|
|
|
|
/// </summary>
|
|
|
|
public async Task ResetAsync() |
|
|
|
{ |
|
|
|
await BomsCycle().ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|