public static void RegisterJobs() { string cron = "0 */30 * ? * *"; //CronJob.AddOrUpdate(GenerateJobInfo(typeof(JsonTransformationJob), cron)); CronJob.AddOrUpdate(GenerateJobInfo(typeof(SqlTransformationJob), cron)); }
public void ConfigureServices(IServiceCollection services) { var appConfiguration = Configuration.GetSection(AppConfiguration.Section).Get <AppConfiguration>(); var csvFileHandlerJobConfig = Configuration.GetSection(CsvFileHandlerJobConfig.Section).Get <CsvFileHandlerJobConfig>(); services.AddAppConfig(Configuration); services.AddAppServices(); services.AddHangfire(x => { x.SetDataCompatibilityLevel(CompatibilityLevel.Version_170) .UseSimpleAssemblyNameTypeSerializer() .UseRecommendedSerializerSettings() .UseSQLiteStorage(appConfiguration.SQLiteDBConn) .UseNLogLogProvider(); var csvFileJob = JobsHelper.GenerateJobInfo( typeof(TestCsvFileHandlerJob), csvFileHandlerJobConfig.JobCron, appConfiguration.TimeZoneId ); CronJob.AddOrUpdate(csvFileJob); }); services.AddHangfireServer(); }
/// <summary> Executes the schedule asynchronous operation. </summary> /// <typeparam name="TJob"> Type of the job. </typeparam> /// <typeparam name="TJobData"> Type of the job data. </typeparam> /// <param name="args"> The arguments. </param> /// <returns> An asynchronous result. </returns> public Task ExecuteScheduleAsync <TJob, TJobData>(TJobData args) where TJob : IBackgroundJob, new() where TJobData : IJobData { CronJob.AddOrUpdate <TJob>(j => j.Execute(null), args); return(Task.FromResult(0)); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddHangfire(r => { r.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection")); r.UseConsole(); r.UseDefaultActivator(); CronJob.AddOrUpdate("Jobs/hangfireJobs.json"); }); }
private void OnChanged(object sender, FileSystemEventArgs e) { lock (_fileWatcherLock) { _logger.Info($"File {e.Name} changed, try to reload configuration again..."); var recurringJobInfos = Load().ToArray(); if (recurringJobInfos == null || recurringJobInfos.Length == 0) { return; } CronJob.AddOrUpdate(recurringJobInfos); } }
/// <summary> /// Builds Hangfire.RecurringJob automatically with the array of Hangfire.RecurringJobExtensions.RecurringJobInfo. /// </summary> public void AddOrUpdate(params RecurringJobInfo[] recurringJobInfos) { CronJob.AddOrUpdate(recurringJobInfos); }
/// <summary> /// Builds Hangfire.RecurringJob automatically by using a JSON configuration. /// </summary> public void AddOrUpdate(string[] jsonFiles, bool reloadOnChange = true) { CronJob.AddOrUpdate(jsonFiles, reloadOnChange); }
/// <summary> /// Builds Hangfire.RecurringJob automatically within specified interface or class. /// </summary> public void AddOrUpdate(Func <IEnumerable <Type> > typesProvider) { CronJob.AddOrUpdate(typesProvider); }
/// <summary> /// Builds Hangfire.RecurringJob automatically within specified interface or class. /// </summary> public void AddOrUpdate(params Type[] types) { CronJob.AddOrUpdate(types); }
/// <summary> /// Builds Hangfire.RecurringJob automatically within specified interface or class. /// </summary> public void AddOrUpdate <TJob>() where TJob : IRecurringJob { CronJob.AddOrUpdate(typeof(TJob)); }