public static string GetCronIntervalByMinutes(int interval) { var result = string.Empty; switch (interval) { case 10: result = Cron.MinuteInterval(10); break; case 60: result = Cron.HourInterval(GetFullHoursByMinutes(60)); break; case 180: result = Cron.HourInterval(GetFullHoursByMinutes(180)); break; case 720: result = Cron.HourInterval(GetFullHoursByMinutes(720)); break; case 1440: result = Cron.DayInterval(GetFullDaysByMinutes(1440)); break; } return(result); }
public IActionResult SendEmailEveryXDay([Bind] EmailEntity model, string time, CancellationToken ct) { var dummyDays = int.Parse(time); RecurringJob.AddOrUpdate(() => _emailService.SendAsync(model, ct), Cron.DayInterval(dummyDays)); return(Ok()); }
public IActionResult Job() { //BackgroundJob.Enqueue(() => entityService.UpdateOpri()); //RecurringJob.AddOrUpdate(() => entityService.UpdateOpri(), Cron.Daily); RecurringJob.AddOrUpdate(() => entityService.UpdateOpri(), Cron.DayInterval(1)); return(Ok()); }
public void ClearOldDataJob() { DbOpperations db = new DbOpperations(); RecurringJob.AddOrUpdate( () => db.DeleteDataOderThanDays(2), Cron.DayInterval(3)); }
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); } }
public void Cron_DayInterval_ReturnsACronExpressionTahtFiresEveryXDays() { // Given var expressionOne = Cron.DayInterval(interval: 1); // When var timeOne = expressionOne.GetNextOccurrence(Now); var timeTwo = expressionOne.GetNextOccurrence(Now.AddDays(1).AddHours(10)); // Then Assert.Equal(Now.AddDays(1), timeOne); Assert.Equal(Now.AddDays(2), timeTwo); }
public void StartPageChangeChecking(PageDto pageDto) { if (pageDto.RefreshRate == RefreshRateEnum.Day) { RecurringJob.AddOrUpdate(pageDto.PageId.ToString(), () => CheckChange(pageDto.PageId) , Cron.DayInterval(1)); } else { RecurringJob.AddOrUpdate(pageDto.PageId.ToString(), () => CheckChange(pageDto.PageId) , Cron.MinuteInterval(Convert.ToInt32(pageDto.RefreshRate))); } }
public void LoadScheduleJob() { // Send failed Consultix transaction every 15 minutes RecurringJob.AddOrUpdate <ConsultixRetryJob>("ConsultixRetryJob", job => job.Process(), Cron.MinuteInterval(15)); // Test job everyday RecurringJob.AddOrUpdate(() => new FilePurgeJob().Process(), Cron.DayInterval(1)); // Test job every 1 minute // RecurringJob.AddOrUpdate(() => new TestJob().Process(), Cron.MinuteInterval(1)); // Purge data every day // RecurringJob.AddOrUpdate<DataPurgeJob>("DataPurgeJob", job => job.Process(), Cron.Daily); }
public string GetCronExpression(IntervalType intervalType, int value) { switch (intervalType) { case IntervalType.Minutely: return(Cron.MinuteInterval(value)); case IntervalType.Hourly: return(Cron.HourInterval(value)); case IntervalType.Daily: return(Cron.DayInterval(value)); case IntervalType.Monthly: return(Cron.MonthInterval(value)); } throw new Exception("please select a valid interval type"); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); System.Web.Http.GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var db = new HangfireContext(); Hangfire.GlobalConfiguration.Configuration.UseSqlServerStorage(db.Database.Connection.ConnectionString); _backgroundJobServer = new BackgroundJobServer(); //Run this job every egiht hours RecurringJob.AddOrUpdate(() => OperateCars(), Cron.HourInterval(8)); //Run this job every three days RecurringJob.AddOrUpdate(() => OperateFridges(), Cron.DayInterval(3)); }
private static CronExpression ParseScheduleToCron(string schedule) { if (schedule.Length < 2) { return(Cron.Minutely()); } var intervalStr = schedule.Substring(0, schedule.Length - 1); if (!int.TryParse(intervalStr, out var interval)) { return(Cron.Minutely()); } var token = schedule[schedule.Length - 1]; switch (token) { case 's': // return interval; return(Cron.SecondInterval(interval)); case 'm': // return interval * ONE_MINUTE; return(Cron.MinuteInterval(interval)); case 'h': // return interval * ONE_HOUR; return(Cron.HourInterval(interval)); case 'd': return(Cron.DayInterval(interval)); default: return(Cron.Minutely()); } }
private void ConfigureJobs(IServiceProvider serviceProvider, ISchedulesContainer schedulesContainer, IHostingEnvironment env) { schedulesContainer.Add(serviceProvider.GetService <ISchedules <SampleJob> >()); var minutesInDay = 1440; var minutesInWeek = 7200; foreach (var job in schedulesContainer.GetJobs()) { if (job.GetMinutesInterval() >= minutesInWeek) { RecurringJob.AddOrUpdate(() => job.Execute(), Cron.Weekly(DayOfWeek.Saturday)); } else if (job.GetMinutesInterval() >= minutesInDay) { RecurringJob.AddOrUpdate(() => job.Execute(), Cron.DayInterval(job.GetMinutesInterval() / minutesInDay)); } else { RecurringJob.AddOrUpdate(() => job.Execute(), Cron.MinuteInterval(job.GetMinutesInterval())); } } }
public void DayInterval(int interval) { cronString = Cron.DayInterval(interval); }
public static string MediaDatabaseRefresh(JobSettings s) { return(Get(s.MediaDatabaseRefresh, Cron.DayInterval(5))); }
private static void SyncClientAvatars(StandardKernel kernel) { var importService = kernel.Get <IImportService>(); RecurringJob.AddOrUpdate(() => importService.SyncMembersAvatars(), Cron.DayInterval(1)); }
public static void AddTask(M_Content_ScheTask scheMod) { if (scheMod.ID < 1) { throw new Exception("任务未正确存储"); } switch (scheMod.ExecuteType) { case (int)M_Content_ScheTask.ExecuteTypeEnum.JustOnce: BackgroundJob.Enqueue <HF_Task_ExecuteSql>(x => x.Execute(scheMod)); break; case (int)M_Content_ScheTask.ExecuteTypeEnum.EveryDay: RecurringJob.AddOrUpdate <HF_Task_ExecuteSql>(scheMod.TaskFlag, x => x.Execute(scheMod), Cron.DayInterval(1)); break; case (int)M_Content_ScheTask.ExecuteTypeEnum.EveryMonth: RecurringJob.AddOrUpdate <HF_Task_ExecuteSql>(scheMod.TaskFlag, x => x.Execute(scheMod), Cron.Monthly); break; case (int)M_Content_ScheTask.ExecuteTypeEnum.Interval: RecurringJob.AddOrUpdate <HF_Task_ExecuteSql>(scheMod.TaskFlag, x => x.Execute(scheMod), Cron.MinuteInterval(Convert.ToInt32(scheMod.ExecuteTime))); break; case (int)M_Content_ScheTask.ExecuteTypeEnum.Passive: break; } }
public string ConvertToCronString() { switch (PatternType) { case PatternTypes.Hourly: Requires.NonNull(HourlyPattern, nameof(HourlyPattern)); Requires.Valid(HourlyPattern, nameof(HourlyPattern)); return(Cron.HourInterval(Convert.ToInt32(HourlyPattern.EveryNHours))); case PatternTypes.Daily: Requires.NonNull(DailyPattern, nameof(DailyPattern)); Requires.Valid(DailyPattern, nameof(DailyPattern)); if (DailyPattern.EveryNDays > 0) { return(Cron.DayInterval(Convert.ToInt32(DailyPattern.EveryNDays))); } if (DailyPattern.EveryWeekday) { var startTimeHour = StartTimeUtc.Hour.ToString(); var startTimeMinute = StartTimeUtc.Minute.ToString(); return($"{startTimeMinute} {startTimeHour} * * 1-5"); } break; case PatternTypes.Weekly: Requires.NonNull(WeeklyPattern, nameof(WeeklyPattern)); Requires.Valid(WeeklyPattern, nameof(WeeklyPattern)); if (WeeklyPattern.RecurEveryNWeeksOn == 1) { var dayString = ""; //TODO: Test trailing comma if (WeeklyPattern.Monday) { dayString += "1,"; } if (WeeklyPattern.Tuesday) { dayString += "2,"; } if (WeeklyPattern.Wednesday) { dayString += "3,"; } if (WeeklyPattern.Thursday) { dayString += "4,"; } if (WeeklyPattern.Friday) { dayString += "5,"; } if (WeeklyPattern.Saturday) { dayString += "6,"; } if (WeeklyPattern.Sunday) { dayString += "7,"; } var startTimeHour = StartTimeUtc.Hour.ToString(); var startTimeMinute = StartTimeUtc.Minute.ToString(); return($"{startTimeMinute} {startTimeHour} 12 ? * {dayString} *"); } else { throw new NotImplementedException(); } case PatternTypes.Monthly: throw new NotImplementedException(); case PatternTypes.Yearly: throw new NotImplementedException(); default: throw new UnexpectedSwitchValueException(PatternType); } return(""); }
public static string RefreshMetadata(JobSettings s) { return(Get(s.RefreshMetadata, Cron.DayInterval(3))); }
public static void RegisterJob() { //测试用例 RecurringJob.AddOrUpdate <TestJob>(x => x.Execute(), Cron.DayInterval(1)); }