public static async Task <IApplicationBuilder> UseScheduledTasks <TPlan>(this IApplicationBuilder app, string pathMatch = "/olive-trigger-tasks") where TPlan : BackgroundJobsPlan, new() { if (!Config.Get <bool>("Automated.Tasks:Enabled")) { return(app); } var plan = Context.Current.GetService <BackgroundJobsPlan>(); plan.Initialize(); foreach (var job in BackgroundJobsPlan.Jobs.Values) { Log.For <IBackgourndTask>() .Info("Registering " + job.Name + " cron : " + job.ScheduleCron + " -> " + CronParser.Minutes(job.ScheduleCron) + " minutes"); await Engine.Register(job.Name, job.Action, CronParser.Minutes(job.ScheduleCron), job.TimeoutInMinutes).ConfigureAwait(false); } app.Map(pathMatch, x => x.UseMiddleware <DistributedBackgroundTasksMiddleware>()); return(app); }
public static async Task <IApplicationBuilder> UseScheduledTasks <TPlan>(this IApplicationBuilder app, string pathMatch = "/olive-trigger-tasks") where TPlan : BackgroundJobsPlan, new() { if (Config.Get <bool>("Automated.Tasks:Enabled")) { var plan = new TPlan(); plan.Initialize(); foreach (var job in BackgroundJobsPlan.Jobs.Values) { app.Logger().Info("Registering " + job.Name); await BackgroundProcessManager.Current.Register(job.Name, job.Action, CronParser.Minutes(job.ScheduleCron), job.TimeoutInMinutes); app.Logger().Info("Registered " + job.Name); } app.Map(pathMatch, x => x.UseMiddleware <DistributedBackgroundTasksMiddleware>()); } return(app); }