public void Configuration(IAppBuilder app) { app.UseHangfireDashboard("/admin", new DashboardOptions { Authorization = new[] { new MyAuthorizationFilter() } }); HangfireJobs.StartJobs(); }
public static void Configure() { try { RecurringJob.AddOrUpdate("Nazwa zadania", () => HangfireJobs.DeleteGallery(), Cron.Minutely); } catch (Exception ex) { Logger.Error(ex, "Hangfire exception"); } }
/// <summary> /// 加载Job /// </summary> public static void LoadJobs() { foreach (var an in HangfireJobs.GroupBy(c => c.AssemblyName)) { Assembly assembly = Assembly.Load(new AssemblyName(an.Key)); foreach (var t in an) { Type type = assembly.GetType(t.ClassName); var task = JobActivator.Current.ActivateJob(type) as IJob; if (task == null) { continue; } if (t.Enable) { RecurringJob.AddOrUpdate(t.JobName, () => task.Run(), t.Cron, timeZone: TimeZoneInfo.Local); } else { RecurringJob.RemoveIfExists(t.JobName); } } } }