diff --git a/samples/ASPNetCoreExecutor/DemoJobHandler.cs b/samples/ASPNetCoreExecutor/DemoJobHandler.cs
new file mode 100644
index 0000000..70d65a7
--- /dev/null
+++ b/samples/ASPNetCoreExecutor/DemoJobHandler.cs
@@ -0,0 +1,20 @@
+using System.Threading.Tasks;
+using DotXxlJob.Core;
+using DotXxlJob.Core.Model;
+
+namespace ASPNetCoreExecutor
+{
+ ///
+ /// 示例Job,只是写个日志
+ ///
+ [JobHandler("demoJobHandler")]
+ public class DemoJobHandler:AbstractJobHandler
+ {
+ public override Task Execute(JobExecuteContext context)
+ {
+ context.JobLogger.Log("receive demo job handler,parameter:{0}",context.JobParameter);
+
+ return Task.FromResult(ReturnT.SUCCESS);
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/ASPNetCoreExecutor/Program.cs b/samples/ASPNetCoreExecutor/Program.cs
index f446a2f..8095f4f 100644
--- a/samples/ASPNetCoreExecutor/Program.cs
+++ b/samples/ASPNetCoreExecutor/Program.cs
@@ -19,6 +19,11 @@ namespace ASPNetCoreExecutor
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
+ .ConfigureLogging((ctx, builder) =>
+ {
+ builder.AddConfiguration(ctx.Configuration);
+ builder.AddConsole();
+ })
.UseStartup();
}
}
\ No newline at end of file
diff --git a/samples/ASPNetCoreExecutor/Startup.cs b/samples/ASPNetCoreExecutor/Startup.cs
index 34bd494..1ae88f9 100644
--- a/samples/ASPNetCoreExecutor/Startup.cs
+++ b/samples/ASPNetCoreExecutor/Startup.cs
@@ -23,13 +23,15 @@ namespace ASPNetCoreExecutor
services.AddXxlJobExecutor(Configuration);
services.AddDefaultXxlJobHandlers();// add httpHandler;
+
+ services.AddSingleton(); // 添加自定义的jobHandler
+
+ services.AddAutoRegistry(); // 自动注册
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app,ILoggingBuilder loggerBuilder, IHostingEnvironment env)
+ public void Configure(IApplicationBuilder app,IHostingEnvironment env)
{
- loggerBuilder.AddConsole();
-
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
diff --git a/samples/ASPNetCoreExecutor/appsettings.Development.json b/samples/ASPNetCoreExecutor/appsettings.Development.json
deleted file mode 100644
index e203e94..0000000
--- a/samples/ASPNetCoreExecutor/appsettings.Development.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "Logging": {
- "LogLevel": {
- "Default": "Debug",
- "System": "Information",
- "Microsoft": "Information"
- }
- }
-}
diff --git a/samples/ASPNetCoreExecutor/appsettings.json b/samples/ASPNetCoreExecutor/appsettings.json
index 4772f08..7d418fb 100644
--- a/samples/ASPNetCoreExecutor/appsettings.json
+++ b/samples/ASPNetCoreExecutor/appsettings.json
@@ -6,8 +6,10 @@
},
"xxlJob": {
"adminAddresses":"http://127.0.0.1:8080",
- "appName": "ASPNetCoreExecutor",
+ "appName": "xxl-job-executor-dotnet",
+ "specialBindAddress": "127.0.0.1",
"port": 5000,
+ "autoRegistry":true,
"accessToken": "",
"logRetentionDays": 30
}
diff --git a/src/DotXxlJob.Core/DefaultHandlers/HttpJobHandler.cs b/src/DotXxlJob.Core/DefaultHandlers/HttpJobHandler.cs
deleted file mode 100644
index 0a14399..0000000
--- a/src/DotXxlJob.Core/DefaultHandlers/HttpJobHandler.cs
+++ /dev/null
@@ -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 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;
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/DotXxlJob.Core/DefaultHandlers/SimpleHttpJobHandler.cs b/src/DotXxlJob.Core/DefaultHandlers/SimpleHttpJobHandler.cs
new file mode 100644
index 0000000..01eaa9f
--- /dev/null
+++ b/src/DotXxlJob.Core/DefaultHandlers/SimpleHttpJobHandler.cs
@@ -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 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;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/DotXxlJob.Core/Internal/IPUtility.cs b/src/DotXxlJob.Core/Internal/IPUtility.cs
new file mode 100644
index 0000000..7a4a7e4
--- /dev/null
+++ b/src/DotXxlJob.Core/Internal/IPUtility.cs
@@ -0,0 +1,7 @@
+namespace DotXxlJob.Core
+{
+ public class IPUtility
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/src/DotXxlJob.Core/Internal/Preconditions.cs b/src/DotXxlJob.Core/Internal/Preconditions.cs
new file mode 100644
index 0000000..52c32f2
--- /dev/null
+++ b/src/DotXxlJob.Core/Internal/Preconditions.cs
@@ -0,0 +1,7 @@
+namespace DotXxlJob.Core
+{
+ public class Preconditions
+ {
+
+ }
+}
\ No newline at end of file