28 lines
877 B
C#
28 lines
877 B
C#
using Quartz;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace VolPro.Warehouse.Services;
|
|
|
|
public class SyncDevicesJob : IJob
|
|
{
|
|
public async Task Execute(IJobExecutionContext context)
|
|
{
|
|
var sp = (IServiceProvider)context.JobDetail.JobDataMap["ServiceProvider"];
|
|
var gwSvc = sp.GetService<Igateway_nodesService>();
|
|
var httpFactory = sp.GetService<IHttpClientFactory>();
|
|
|
|
var onlineNodes = await gwSvc.FindAsIQueryable(x => x.IsOnline == "在线" && x.Enable == "启用" && x.BaseUrl != null)
|
|
.ToListAsync();
|
|
|
|
foreach (var node in onlineNodes)
|
|
{
|
|
try
|
|
{
|
|
var http = httpFactory.CreateClient();
|
|
await http.PostAsync($"{node.BaseUrl}/api/gateway/devices/sync?adapter={node.AdapterTypes}", null);
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
}
|