Yuebon.NetCore/Yuebon.Quartz.Jobs/HttpResultfulJob.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using MediatR;
using Yuebon.Email.CommandHandler;
namespace Yuebon.Quartz.Jobs;
/// <summary>
/// 处理远程接口url的定时任务
/// </summary>
public class HttpResultfulJob : IJob
{
private readonly ITaskManagerService _iService;
private IMediator _mediatR;
public HttpResultfulJob(ITaskManagerService iService, IMediator mediatR)
{
_iService = iService;
_mediatR= mediatR;
}
/// <summary>
/// 执行远程接口url的定时任务
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public Task Execute(IJobExecutionContext context)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
AbstractTrigger trigger = (context as JobExecutionContextImpl).Trigger as AbstractTrigger;
string sqlWhere = string.Format("Id='{0}' and GroupName='{1}'", trigger.Name, trigger.Group);
TaskManager taskManager = _iService.GetWhere(sqlWhere);
string httpMessage = "";
if (taskManager == null)
{
FileQuartz.WriteErrorLog($"任务不存在");
return Task.Delay(1);
}
FileQuartz.InitTaskJobLogPath(taskManager.Id);
string msg = $"开始时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff")}";
//记录任务执行记录
_iService.RecordRun(taskManager.Id, JobAction.开始, true, msg);
if (string.IsNullOrEmpty(taskManager.JobCallAddress) || taskManager.JobCallAddress == "/")
{
FileQuartz.WriteErrorLog($"{ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff")}未配置任务地址,");
_iService.RecordRun(taskManager.Id, JobAction.结束, false, "未配置任务地址");
return Task.Delay(1);
}
try
{
Dictionary<string, string> header = new Dictionary<string, string>();
if (!string.IsNullOrEmpty(taskManager.JobCallParams))
{
httpMessage = HttpClientHelper.Post(taskManager.JobCallParams, taskManager.JobCallAddress, header);
}
else
{
httpMessage = HttpClientHelper.HttpGet(taskManager.JobCallAddress);
}
stopwatch.Stop();
string resume = $"结束时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff")} 共耗时{stopwatch.ElapsedMilliseconds} 毫秒\r\n";
_iService.RecordRun(taskManager.Id, JobAction.结束, true, resume, $"消息:{ httpMessage ?? "OK"}");
后面还有 44 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。