public static string PrepareCronType(CronSelectorModel model) { switch (model.CronType) { case CronType.Daily: return(Cron.Daily(model.Hour, model.Minute)); case CronType.Hourly: return(Cron.Hourly(model.Minute)); case CronType.Minutely: return(Cron.Minutely()); case CronType.Monthly: return(Cron.Monthly(model.Day, model.Hour, model.Minute)); case CronType.Weekly: return(Cron.Weekly(DayOfWeek.Monday, model.Hour, model.Minute)); case CronType.Yearly: return(Cron.Yearly(model.Month, model.Day, model.Hour, model.Minute)); } return(string.Empty); }
/// <summary> /// Get the cron expression from the recurring options /// </summary> /// <param name="recurringOptions"></param> /// <returns></returns> private string GetCronExpression(RecurringOption recurringOptions) { var cronExpression = string.Empty; recurringOptions.Day = recurringOptions.Day == 0 ? 1 : recurringOptions.Day; switch (recurringOptions.Recurrence) { case Recurrence.Daily: cronExpression = Cron.Daily(recurringOptions.Hour, recurringOptions.Minute); break; case Recurrence.Hourly: cronExpression = Cron.Hourly(recurringOptions.Minute); break; case Recurrence.Minutely: cronExpression = Cron.Minutely(); break; case Recurrence.Monthly: cronExpression = Cron.Monthly(recurringOptions.Day, recurringOptions.Hour, recurringOptions.Minute); break; case Recurrence.Weekly: cronExpression = Cron.Weekly(recurringOptions.DayOfWeek, recurringOptions.Hour, recurringOptions.Minute); break; case Recurrence.Yearly: cronExpression = Cron.Yearly(recurringOptions.Month, recurringOptions.Day, recurringOptions.Hour, recurringOptions.Minute); break; } return(cronExpression); }
public static void InitializeJobs() { RecurringJob.AddOrUpdate <SendPaymentReminder>(job => job.Execute(), Cron.Monthly(25, 12)); RecurringJob.AddOrUpdate <SendLeaseReminder>(job => job.Execute(), Cron.Daily(12)); RecurringJob.AddOrUpdate <testReminder>(job => job.Execute(), Cron.Daily(15)); RecurringJob.AddOrUpdate <SendDepositReminder>(job => job.Execute(), Cron.Daily(15)); }
public void IniciarJob(IndicadorAutomaticoViewModel indicadorAutomatico) { switch (indicadorAutomatico.CategoriaIndicadorAutomatico) { case Enums.Enum.CategoriaIndicadorAutomatico.CPI: RecurringJob.AddOrUpdate <IndicadorAutomaticoCPIStrategy>( indicadorAutomatico.Nombre, x => x.EjecutarIndicador(indicadorAutomatico.IndicadorViewModel), //Cron.Minutely); Cron.Monthly(5, 1, 0)); // El 5 de cada mes a la 1:00 a.m. break; case Enums.Enum.CategoriaIndicadorAutomatico.CPI_Servicios: RecurringJob.AddOrUpdate <IndicadorAutomaticoCPIServiciosStrategy>( indicadorAutomatico.Nombre, x => x.EjecutarIndicador(indicadorAutomatico.IndicadorViewModel), //Cron.Minutely); Cron.Monthly(5, 1, 15)); // El 5 de cada mes a la 1:15 a.m. break; case Enums.Enum.CategoriaIndicadorAutomatico.CPI_Llave_En_Mano: RecurringJob.AddOrUpdate <IndicadorAutomaticoCPILlaveManoStrategy>( indicadorAutomatico.Nombre, x => x.EjecutarIndicador(indicadorAutomatico.IndicadorViewModel), //Cron.Minutely); Cron.Monthly(5, 1, 30)); // El 5 de cada mes a la 1:30 a.m. break; } }
public void Monthly_WithoutDayHourMinute_ReturnsFormattedStringWithDefaults() { string expected = "0 0 1 * *"; string actual = Cron.Monthly(); Assert.Equal(expected, actual); }
public void GetDescription_CronMonthlyWithDay_ReturnsAtMidnightOnDay5() { string expected = "At 00:00 AM, on day 5 of the month"; string actual = Cron.GetDescription(Cron.Monthly(5)); Assert.Equal(expected, actual); }
// 执行的时间表。关于 CRON 详细信息,见 https://en.wikipedia.org/wiki/Cron#CRON_expression private string ConvertToCronExpression(ScheduleCronOptions cronOptions) { switch (cronOptions.scheduleCron) { case ScheduleCron.Minutely: return(Cron.Minutely()); case ScheduleCron.Hourly: return(Cron.Hourly(cronOptions.Minute)); case ScheduleCron.Daily: return(Cron.Daily(cronOptions.Hour, cronOptions.Minute)); case ScheduleCron.Weekly: return(Cron.Weekly((DayOfWeek)cronOptions.Week, cronOptions.Hour, cronOptions.Minute)); case ScheduleCron.Monthly: return(Cron.Monthly(cronOptions.Day, cronOptions.Hour, cronOptions.Minute)); case ScheduleCron.Yearly: return(Cron.Yearly(cronOptions.Month, cronOptions.Day, cronOptions.Hour, cronOptions.Minute)); default: throw new InvalidOperationException("Can not convert the scheduleCronOptions to cron."); } }
public void Configuration(IAppBuilder app) { ConfigureAuth(app); app.UseHangfireAspNet(GetHangfireConfiguration); app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new IDashboardAuthorizationFilter[0] }); IIndicadorAutomaticoService indicadorAutomaticoService = (IIndicadorAutomaticoService)KernelNinject.GetService(typeof(IIndicadorAutomaticoService)); indicadorAutomaticoService.GenerarJobsTareasAutomaticas(); RecurringJob.AddOrUpdate <NotificacionService>( "NotificarCarga", x => x.NotificarCarga(), //Cron.Minutely); Cron.Monthly(1, 2, 0)); // Cada 1º de mes a las 2 a.m. RecurringJob.AddOrUpdate <NotificacionService>( "NotificarMetas", x => x.NotificarMetas(), //Cron.Minutely); Cron.Daily(3, 0)); // Cada día a las 3 a.m. RecurringJob.AddOrUpdate <AnioTableroService>( "ProcesoHabilitarAnioSiguiente", x => x.ProcesoHabilitarAnioSiguiente(), Cron.Yearly(12, 31, 23, 0)); }
public void GetDescription_CronMonthlyWithDayHourMinute_ReturnsAtFiveFifteenAMOnDay5() { string expected = "At 05:15 AM, on day 5 of the month"; string actual = Cron.GetDescription(Cron.Monthly(5, 5, 15)); Assert.Equal(expected, actual); }
public void GenerarJobsTareasAutomaticas() { IList <IndicadorAutomaticoViewModel> indicadoresAutomaticos = this.Todos(); foreach (IndicadorAutomaticoViewModel indicadorAutomatico in indicadoresAutomaticos) { switch (indicadorAutomatico.CategoriaIndicadorAutomatico) { case Enums.Enum.CategoriaIndicadorAutomatico.CPI: RecurringJob.AddOrUpdate <IndicadorAutomaticoCPIStrategy>( indicadorAutomatico.Nombre, x => x.EjecutarIndicador(indicadorAutomatico.IndicadorViewModel), //Cron.Minutely); Cron.Monthly(5, 1, 0)); // El 5 de cada mes a la 1:00 a.m. break; case Enums.Enum.CategoriaIndicadorAutomatico.CPI_Servicios: RecurringJob.AddOrUpdate <IndicadorAutomaticoCPIServiciosStrategy>( indicadorAutomatico.Nombre, x => x.EjecutarIndicador(indicadorAutomatico.IndicadorViewModel), //Cron.Minutely); Cron.Monthly(5, 1, 15)); // El 5 de cada mes a la 1:15 a.m. break; case Enums.Enum.CategoriaIndicadorAutomatico.CPI_Llave_En_Mano: RecurringJob.AddOrUpdate <IndicadorAutomaticoCPILlaveManoStrategy>( indicadorAutomatico.Nombre, x => x.EjecutarIndicador(indicadorAutomatico.IndicadorViewModel), //Cron.Minutely); Cron.Monthly(5, 1, 30)); // El 5 de cada mes a la 1:30 a.m. break; } } }
/// <summary> /// Static method to start the recurring job. /// </summary> public static void StartRecurringJob() { var cronPeriod = Environment.GetEnvironmentVariable("MORPHIC_CHECK_STALE_USERS_CRON_PERIOD"); if (string.IsNullOrWhiteSpace(cronPeriod)) { cronPeriod = DefaultCronPeriod; } switch (cronPeriod.ToLower()) { case "disabled": // don't run the job. Delete if exists. RecurringJob.RemoveIfExists(JobId); return; case "daily": cronPeriod = Cron.Daily(); break; case "weekly": cronPeriod = Cron.Weekly(DayOfWeek.Sunday); break; case "monthly": cronPeriod = Cron.Monthly(); break; case "minutely": // probably only useful for development and or some rare situations! cronPeriod = Cron.Minutely(); break; } RecurringJob.AddOrUpdate <UserCleanupJob>(JobId, userCleanup => userCleanup.DeleteStaleUsers(), cronPeriod); }
public void Monthly_WithoutHourMinuteWithDay_ReturnsFormattedStringWithDay() { int day = 6; string expected = "0 0 " + day.ToString() + " * *"; string actual = Cron.Monthly(day); Assert.Equal(expected, actual); }
/// <summary> /// hangfire初始化 /// </summary> public static void Start() { RecurringJob.AddOrUpdate <IHangfireBackJob>(job => job.CheckLinks(), "0 */5 * * *"); //每5h检查友链 RecurringJob.AddOrUpdate <IHangfireBackJob>(job => job.EverydayJob(), Cron.Daily(5), TimeZoneInfo.Local); //每天的任务 RecurringJob.AddOrUpdate <IHangfireBackJob>(job => job.CreateLuceneIndex(), Cron.Weekly(DayOfWeek.Monday, 5), TimeZoneInfo.Local); //每周的任务 RecurringJob.AddOrUpdate <IHangfireBackJob>(job => job.EverymonthJob(), Cron.Monthly(1, 0, 0), TimeZoneInfo.Local); //每月的任务 RecurringJob.AddOrUpdate <IHangfireBackJob>(job => job.StatisticsSearchKeywords(), Cron.Hourly); //每小时的任务 BackgroundJob.Enqueue <IHangfireBackJob>(job => job.StatisticsSearchKeywords()); }
public void Monthly_WithoutMinuteWithDayHour_ReturnsFormattedStringWithDayHour() { int day = 7; int hour = 4; string expected = "0 " + hour.ToString() + " " + day.ToString() + " * *"; string actual = Cron.Monthly(day, hour); Assert.Equal(expected, actual); }
public void InitTaskList() { #region 逾期宽限期利息计算 //每天0点05分中计算所有账单的逾期宽限期利息,冻结企业状态,计算分销逾期和宽限期次数 RecurringJob.AddOrUpdate(() => OverDueMonthlyBill.Execute(), Cron.Daily(0, 5), TimeZoneInfo.Local); //每个月1号0点9分执行保险月限额恢复 RecurringJob.AddOrUpdate(() => updateMonthlylimitCountService.Execute(), Cron.Monthly(1, 0, 9), TimeZoneInfo.Local); #endregion }
/// <summary> /// hangfire初始化 /// </summary> public static void Start() { RecurringJob.AddOrUpdate(() => CheckLinks(), "0 */5 * * *"); //每5h检查友链 RecurringJob.AddOrUpdate(() => EverydayJob(), Cron.Daily(5), TimeZoneInfo.Local); //每天的任务 RecurringJob.AddOrUpdate(() => EveryweekJob(), Cron.Weekly(DayOfWeek.Monday, 5), TimeZoneInfo.Local); //每周的任务 RecurringJob.AddOrUpdate(() => EverymonthJob(), Cron.Monthly(1, 0, 0), TimeZoneInfo.Local); //每月的任务 RecurringJob.AddOrUpdate(() => EveryHourJob(), Cron.Hourly); //每小时的任务 BackgroundJob.Enqueue(() => HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.StatisticsSearchKeywords), "default")); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); JobStorage.Current = new SqlServerStorage(System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString); RecurringJob.AddOrUpdate(() => ChangeService.Instance.ApplyChanges(), Cron.Monthly(1)); RecurringJob.AddOrUpdate(() => EmailSenderService.Instance.Send(), Cron.Monthly(1)); RecurringJob.AddOrUpdate(() => ChangeService.Instance.LockLicense(), Cron.Monthly(5)); }
public void Configuration(IAppBuilder app) { GlobalConfiguration.Configuration.UseSqlServerStorage("PTODataConnectionString"); app.UseHangfireDashboard(); app.UseHangfireServer(); RecurringJob.AddOrUpdate("AutoAccrue", () => AutoAccrue(), Cron.Monthly(1)); RecurringJob.AddOrUpdate("ConvertRequestsToHistory", () => ConvertRequestsToHistory(), Cron.Daily(8)); }
public void Monthly_WithDayHourMinute_ReturnsFormattedStringWithDayHourMinute() { int day = 7; int hour = 4; int minute = 23; string expected = minute.ToString() + " " + hour.ToString() + " " + day.ToString() + " * *"; string actual = Cron.Monthly(day, hour, minute); Assert.Equal(expected, actual); }
public static void Schedule() { RecurringJob .AddOrUpdate <IAtualizarEstoqueJob>( recurringJobId: "AtualizarEstoque", methodCall: job => job.Run(), cronExpression: Cron.Monthly(14) //cronExpression: "0 0 0/1 ? * SUN,SAT *" //timeZone: TimeZoneInfo.FindSystemTimeZoneById("America/Fortaleza") ); }
public async Task Job(List <PostalCode> postalCodes, PropertyType propertyType, ProcessType processType, bool isScheduled, ScheduleInterval?scheduleInterval, ProxyIp proxyIp) { var process = InsertProcess(processType, propertyType); if (isScheduled) { var cron = Cron.Daily(); switch (scheduleInterval) { case ScheduleInterval.Monthly: cron = Cron.Monthly(); break; case ScheduleInterval.Daily: cron = Cron.Daily(); break; case ScheduleInterval.Once_in_2_Days: cron = Cron.DayInterval(2); break; case ScheduleInterval.Once_in_4_Days: cron = Cron.DayInterval(4); break; case ScheduleInterval.Twice_a_Month: cron = Cron.DayInterval(15); break; case ScheduleInterval.Weekly: cron = Cron.DayInterval(7); break; default: break; } RecurringJob.AddOrUpdate( () => Recurrency(postalCodes, propertyType, process, proxyIp, processType), cron); } else { var jobId = BackgroundJob.Enqueue(() => _crawlerService.Execute(postalCodes, propertyType, process, proxyIp, processType)); if (int.TryParse(jobId, out int temp)) { UpdateProcess(temp, process); } //update process status BackgroundJob.ContinueJobWith(jobId, () => Execute(jobId, process.Id), JobContinuationOptions.OnAnyFinishedState); } }
private string GetCronExpression(RefreshFrequent refreshFrequent) { return(refreshFrequent switch { RefreshFrequent.Minutely => Cron.Minutely(), RefreshFrequent.Quarterly => "*/15 * * * *", RefreshFrequent.Hourly => Cron.Hourly(), RefreshFrequent.Daily => Cron.Daily(2), RefreshFrequent.Weekly => Cron.Weekly(), RefreshFrequent.Monthly => Cron.Monthly(), RefreshFrequent.Yearly => Cron.Yearly(), _ => throw new NotImplementedException() });
public void RunOnSchedule(int id, string name, string recurring, Dictionary <string, string> psParams) { var recurringSwitch = new Dictionary <string, string> { { "Minutely", Cron.Minutely() }, { "Hourly", Cron.Hourly() }, { "Weekly", Cron.Weekly() }, { "Monthly", Cron.Monthly() }, { "Yearly", Cron.Yearly() } }; RecurringJob.AddOrUpdate(id.ToString(), () => Run(name, psParams), recurringSwitch[recurring]); }
public void RunOnSchedule(int id, string name, string recurring, Dictionary <string, string> psParams, DateTime schedule) { var recurringSwitch = new Dictionary <string, string> { { "Minutely", Cron.Minutely() }, { "Hourly", Cron.Hourly(schedule.Minute) }, { "Daily", Cron.Daily(schedule.Hour, schedule.Minute) }, { "Weekly", Cron.Weekly(schedule.DayOfWeek, schedule.Hour, schedule.Minute) }, { "Monthly", Cron.Monthly(schedule.Day, schedule.Hour, schedule.Minute) }, { "Yearly", Cron.Yearly(schedule.Month, schedule.Day, schedule.Hour, schedule.Minute) } }; RecurringJob.AddOrUpdate <IJobServices>(id.ToString(), x => x.Run(name, psParams), recurringSwitch[recurring], TimeZoneInfo.Local); }
protected async void RegisterJobInHangfire(Job entity) { if (entity == null || entity.Project == null) { throw new UserFriendlyException("定时任务信息不完整"); } var projectHost = entity.Project.Host; SendRequestJobArgs args = new SendRequestJobArgs() { JobId = entity.Id, Host = projectHost, ApiUrl = entity.ApiUrl }; string cron = Cron.Daily(); switch (entity.Frequency) { case FrequencyEnum.每分钟: cron = Cron.Minutely(); break; case FrequencyEnum.每小时: cron = Cron.Hourly(); break; case FrequencyEnum.每天: cron = Cron.Daily(); break; case FrequencyEnum.每月: cron = Cron.Monthly(); break; default: break; } if (!string.IsNullOrWhiteSpace(entity.Cron)) { cron = entity.Cron; } RecurringJob.AddOrUpdate <SendRequestJob>(entity.Id.ToString(), e => e.Execute(args), cron, TimeZoneInfo.Local); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); app.UseHangfireServer(); app.UseHangfireDashboard(); Hangfire.RecurringJob.AddOrUpdate <StatementCreator>(j => j.Run(), Cron.Monthly(1, 4)); }
public void Configure(IApplicationBuilder applicationBuilder, IWebHostEnvironment environment, TripFlipDbContext tripFlipDbContext) { applicationBuilder.ConfigureExceptionHandler(environment); applicationBuilder.UseRouting(); applicationBuilder.UseAuthentication(); applicationBuilder.UseAuthorization(); applicationBuilder.UseHangfireDashboard(); RecurringJob.AddOrUpdate <IScheduledTaskService>( scheduledTask => scheduledTask.GreetBirthdayUsersAsync(), Cron.Daily(hour: 8)); RecurringJob.AddOrUpdate <IScheduledTaskService>( scheduledTask => scheduledTask.SendUserStatisticAsync(), Cron.Monthly()); applicationBuilder.UseHangfireServer(); applicationBuilder.UseEndpoints(endpoints => { endpoints.MapControllers(); }); var swaggerEndpointUrl = Configuration.GetSection("OpenApiInfo")["url"]; var swaggerApiVersion = Configuration.GetSection("OpenApiInfo")["version"]; applicationBuilder.UseSwagger(); applicationBuilder.UseSwaggerUI(options => { options.SwaggerEndpoint(swaggerEndpointUrl, swaggerApiVersion); options.OAuthClientId(Configuration["GoogleApi:ClientId"]); options.OAuthClientSecret(Configuration["GoogleApi:ClientSecret"]); options.OAuthAppName("TripFlip"); options.OAuthScopeSeparator(" "); options.OAuthUsePkce(); }); tripFlipDbContext.Database.Migrate(); }
public JobReponse CreateMonthlyJob(MonthlyJobRequest request) { JobRequest jobRequest = jobRequestMapper.MapMonthlyJobRequest(request); JobReponse response = new JobReponse(); if (!DoesJobExist(jobRequest.JobName)) { RecurringJob.AddOrUpdate(recurringJobId: jobRequest.JobName.ToLower(), methodCall: () => _jobRepo.CallWebServiceMethod(jobRequest.ServiceUrl, jobRequest.Controller, jobRequest.Action), cronExpression: Cron.Monthly((int)jobRequest.Day, jobRequest.Hour, jobRequest.Minute), timeZone: null, queue: "monthly" ); response.Result = "Job Added"; } else { response.Result = "Job Already Exists : " + jobRequest.JobName; } return(response); }
protected virtual string GetCron(int period) { var time = TimeSpan.FromSeconds(period /= 1000); var cron = ""; if (time.TotalSeconds <= 59) { cron = $"*/{period} * * * * *"; } else if (time.TotalMinutes <= 59) { cron = Cron.Hourly(time.Minutes); } else if (time.TotalHours <= 23) { cron = Cron.Daily(time.Hours, time.Minutes); } else { Cron.Monthly(time.Days, time.Hours, time.Minutes); } return(cron); }
private string MapjobFrequency(CronEnum occurence) { var frequency = Cron.Daily(); switch (occurence) { case CronEnum.Daily: frequency = Cron.Daily(); break; case CronEnum.Minutely: frequency = Cron.Minutely(); break; case CronEnum.Hourly: frequency = Cron.Hourly(); break; case CronEnum.Weekly: frequency = Cron.Weekly(); break; case CronEnum.Monthly: frequency = Cron.Monthly(); break; case CronEnum.Yearly: frequency = Cron.Yearly(); break; default: break; } return(frequency); }