定时任务新增加http请求

This commit is contained in:
不做码农
2022-04-03 13:00:30 +08:00
parent 7377a3e167
commit 2bc336ebb2
8 changed files with 149 additions and 57 deletions

View File

@@ -7,7 +7,7 @@ namespace ZR.Tasks
{
public class JobFactory : IJobFactory
{
private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
/// <summary>
/// 注入反射获取依赖对象
@@ -42,12 +42,10 @@ namespace ZR.Tasks
public void ReturnJob(IJob job)
{
var disposable = job as IDisposable;
if (disposable != null)
if (job is IDisposable disposable)
{
disposable.Dispose();
}
}
}
}

View File

@@ -0,0 +1,33 @@
using Infrastructure;
using Infrastructure.Attribute;
using Quartz;
using Quartz.Impl;
using Quartz.Impl.Triggers;
using System.Threading.Tasks;
using ZR.Service.System.IService;
namespace ZR.Tasks.TaskScheduler
{
[AppService(ServiceType = typeof(Job_HttpRequest), ServiceLifetime = LifeTime.Scoped)]
internal class Job_HttpRequest : JobBase, IJob
{
private readonly ISysTasksQzService tasksQzService;
public Job_HttpRequest(ISysTasksQzService tasksQzService)
{
this.tasksQzService = tasksQzService;
}
public async Task Execute(IJobExecutionContext context)
{
await ExecuteJob(context, async () => await Run(context));
}
public async Task Run(IJobExecutionContext context)
{
AbstractTrigger trigger = (context as JobExecutionContextImpl).Trigger as AbstractTrigger;
var info = await tasksQzService.GetByIdAsync(trigger.Name);
var result = await HttpHelper.HttpPostAsync("http://" + info.ApiUrl, info.JobParams);
//Console.WriteLine(result);
}
}
}