Scheduler.NET is a distributed scheduler system. It support http call back job and client managed job.
-
Create a ASP.NET Core MVC project
-
Install Scheduler.NET package from NUGET
-
AddSchedulerNet after AddMvc
services.AddMvc().AddSchedulerNet(Configuration).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
-
Add UseSchedulerNet in Configure method
app.UseSchedulerNet();
-
Update config file:
"SchedulerNet": { "Hangfire": { "StorageType": "SqlServer", "ConnectionString": "Server=.\\SQLEXPRESS;Database=Scheduler.NET;Trusted_Connection=True;MultipleActiveResultSets=true;" }, "StorageType": "SqlServer", "ConnectionString": "Server=.\\SQLEXPRESS;Database=Scheduler.NET;Trusted_Connection=True;MultipleActiveResultSets=true;", "UseToken": false, "Tokens": [ "a1", "a2" ], "TokenHeader": "SchedulerNET", "IgnoreCrons": [ "* * * * *" ], "Cache": { "Type": "memory" } }
-
Create database: Scheduler.NET in MSSQL
-
Run the web application from port 5000
-
Create a dotnet core Console project
-
Install Scheduler.NET.Client package from NUGET
-
Add a test processor class ConsoleJobProcessor and update main method
public class ConsoleJobProcessor : SimpleJobProcessor { public override bool Process(JobContext context) { Console.WriteLine(JsonConvert.SerializeObject(context)); return true; } } static void Main(string[] args) { SchedulerNetHelper api = new SchedulerNetHelper("http://localhost:5000"); api.CreateJob(new Job { Name = typeof(ConsoleJobProcessor).FullName, Cron = "*/1 * * * *", Group = "Test", Content = "aaa" }); SchedulerNetClient client = new SchedulerNetClient("Test", "http://localhost:5000"); client.Init(); Console.Read(); }
-
Run the console project
-
Create a callbackjob:
SchedulerNetHelper api = new SchedulerNetHelper("http://localhost:5000"); api.CreateCallbackJob(new CallbackJob { Name = "job1", Content = "{}", Cron = "*/1 * * * *", Group = "group1", Method = HttpMethod.Get, Url = "http://www.baidu.com" });
-
Then the scheduler.net will request http://www.baidu.com every 1 minutes.