parent
537c909dfc
commit
eb762784e7
9 changed files with 91 additions and 34 deletions
@ -0,0 +1,20 @@ |
||||
using System.Threading.Tasks; |
||||
using DotXxlJob.Core; |
||||
using DotXxlJob.Core.Model; |
||||
|
||||
namespace ASPNetCoreExecutor |
||||
{ |
||||
/// <summary> |
||||
/// 示例Job,只是写个日志 |
||||
/// </summary> |
||||
[JobHandler("demoJobHandler")] |
||||
public class DemoJobHandler:AbstractJobHandler |
||||
{ |
||||
public override Task<ReturnT> Execute(JobExecuteContext context) |
||||
{ |
||||
context.JobLogger.Log("receive demo job handler,parameter:{0}",context.JobParameter); |
||||
|
||||
return Task.FromResult(ReturnT.SUCCESS); |
||||
} |
||||
} |
||||
} |
||||
@ -1,9 +0,0 @@ |
||||
{ |
||||
"Logging": { |
||||
"LogLevel": { |
||||
"Default": "Debug", |
||||
"System": "Information", |
||||
"Microsoft": "Information" |
||||
} |
||||
} |
||||
} |
||||
@ -1,21 +0,0 @@ |
||||
using System.Threading.Tasks; |
||||
using DotXxlJob.Core.Model; |
||||
|
||||
namespace DotXxlJob.Core.DefaultHandlers |
||||
{ |
||||
[JobHandler("httpJobHandler")] |
||||
public class HttpJobHandler:AbsJobHandler |
||||
{ |
||||
public async override Task<ReturnT> Execute(JobExecuteContext context) |
||||
{ |
||||
if (string.IsNullOrEmpty(context.JobParameter)) |
||||
{ |
||||
return ReturnT.Failed("url is empty"); |
||||
} |
||||
//判断是否为单URL |
||||
context.JobLogger.Log("Get Request Data:{0}",context.JobParameter); |
||||
return ReturnT.SUCCESS; |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,44 @@ |
||||
using System.Net.Http; |
||||
using System.Text.RegularExpressions; |
||||
using System.Threading.Tasks; |
||||
using DotXxlJob.Core.Model; |
||||
|
||||
namespace DotXxlJob.Core.DefaultHandlers |
||||
{ |
||||
[JobHandler("simpleHttpJobHandler")] |
||||
public class SimpleHttpJobHandler:AbsJobHandler |
||||
{ |
||||
private readonly IHttpClientFactory _httpClientFactory; |
||||
|
||||
private static readonly Regex UrlPattern = |
||||
new Regex(@"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]"); |
||||
public SimpleHttpJobHandler(IHttpClientFactory httpClientFactory) |
||||
{ |
||||
this._httpClientFactory = httpClientFactory; |
||||
} |
||||
public async override Task<ReturnT> Execute(JobExecuteContext context) |
||||
{ |
||||
if (string.IsNullOrEmpty(context.JobParameter)) |
||||
{ |
||||
return ReturnT.Failed("url is empty"); |
||||
} |
||||
|
||||
string url = context.JobParameter; |
||||
|
||||
if (!UrlPattern.IsMatch(url)) |
||||
{ |
||||
return ReturnT.Failed("url format is not valid"); |
||||
} |
||||
|
||||
using (var client = _httpClientFactory.CreateClient(Constants.DefaultHttpClientName)) |
||||
{ |
||||
var responseMessage = await client.GetAsync(url); |
||||
} |
||||
|
||||
//判断是否为单URL |
||||
context.JobLogger.Log("Get Request Data:{0}",context.JobParameter); |
||||
return ReturnT.SUCCESS; |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,7 @@ |
||||
namespace DotXxlJob.Core |
||||
{ |
||||
public class IPUtility |
||||
{ |
||||
|
||||
} |
||||
} |
||||
@ -0,0 +1,7 @@ |
||||
namespace DotXxlJob.Core |
||||
{ |
||||
public class Preconditions |
||||
{ |
||||
|
||||
} |
||||
} |
||||
Loading…
Reference in new issue