完善任务调度

This commit is contained in:
橙子
2021-11-03 18:14:44 +08:00
parent 7b994240d0
commit a32ef06c0a
11 changed files with 83 additions and 15 deletions

View File

@@ -5,13 +5,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
namespace Yi.Framework.Job
{
public class HttpJob : IJob
{
private ILogger<VisitJob> _logger;
public HttpJob(ILogger<VisitJob> logger)
private ILogger<HttpJob> _logger;
public HttpJob(ILogger<HttpJob> logger)
{
_logger = logger;
}
@@ -20,7 +21,23 @@ namespace Yi.Framework.Job
{
return Task.Run(() =>
{
var jobData = context.JobDetail.JobDataMap;
string method= jobData[Common.Const.JobConst.method].ToString();
string url = jobData[Common.Const.JobConst.url].ToString();
string data="异常!";
switch (method)
{
case "post":
data = Common.Helper.HttpHelper.HttpPost(url);
break;
case "get":
data = Common.Helper.HttpHelper.HttpGet(url);
break;
}
_logger.LogWarning("定时任务开始调度:" + nameof(HttpJob) + ":" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + $":访问地址为:{url},结果为:{data}");
Console.WriteLine($"结果:{data}");
});
}
}