/// <summary> /// Add a cron task for all devices /// </summary> /// <param name="value"></param> /// <param name="type"></param> /// <returns></returns> public async Task <bool> CronAdd(int value, CronType type = CronType.PowerOff) { return(await Process((Device device) => { return device.CronAdd(value, type); })); }
/// <summary> /// Delete a cron task for all devices /// </summary> /// <param name="type"></param> /// <returns></returns> public async Task <bool> CronDelete(CronType type = CronType.PowerOff) { return(await Process((Device device) => { return device.CronDelete(type); })); }
/// <summary> /// Returns cron expression that fires every hour at the specified minute. /// </summary> /// <param name="minute">The minute in which the schedule will be activated (0-59).</param> /// <param name="type"></param> public static string Hourly(int minute, CronType type = CronType.Quartz) { if (type == CronType.Quartz) { return(string.Format("* {0} * * * ?", minute)); } return(string.Format("{0} * * * *", minute)); }
/// <summary>Returns cron expression that fires every minute.</summary> /// <param name="type"></param> public static string Minutely(CronType type = CronType.Quartz) { if (type == CronType.Quartz) { return("* * * * * ?"); } return("* * * * *"); }
/// <summary> /// Returns cron expression that fires every year at the specified month, day, /// hour and minute in UTC. /// </summary> /// <param name="month">The month in which the schedule will be activated (1-12).</param> /// <param name="day">The day of month in which the schedule will be activated (1-31).</param> /// <param name="hour">The hour in which the schedule will be activated (0-23).</param> /// <param name="minute">The minute in which the schedule will be activated (0-59).</param> /// <param name="type"></param> public static string Yearly(int month, int day, int hour, int minute, CronType type = CronType.Quartz) { if (type == CronType.Quartz) { return(string.Format("* {0} {1} {2} {3} ?", minute, hour, day, month)); } return(string.Format("{0} {1} {2} {3} *", minute, hour, day, month)); }
/// <summary> /// Returns cron expression that fires every month at the specified day of month, /// hour and minute in UTC. /// </summary> /// <param name="day">The day of month in which the schedule will be activated (1-31).</param> /// <param name="hour">The hour in which the schedule will be activated (0-23).</param> /// <param name="minute">The minute in which the schedule will be activated (0-59).</param> /// <param name="type"></param> public static string Monthly(int day, int hour, int minute, CronType type = CronType.Quartz) { if (type == CronType.Quartz) { return(string.Format("* {0} {1} {2} * ?", minute, hour, day)); } return(string.Format("{0} {1} {2} * *", minute, hour, day)); }
/// <summary> /// Returns cron expression that fires every day at the specified hour and minute /// in UTC. /// </summary> /// <param name="hour">The hour in which the schedule will be activated (0-23).</param> /// <param name="minute">The minute in which the schedule will be activated (0-59).</param> /// <param name="type"></param> public static string Daily(int hour, int minute, CronType type = CronType.Quartz) { if (type == CronType.Quartz) { return(string.Format("* {0} {1} * * ?", minute, hour)); } return(string.Format("{0} {1} * * *", minute, hour)); }
/// <summary> /// Returns cron expression that fires every week at the specified day /// of week, hour and minute in UTC. /// </summary> /// <param name="dayOfWeek">The day of week in which the schedule will be activated.</param> /// <param name="hour">The hour in which the schedule will be activated (0-23).</param> /// <param name="minute">The minute in which the schedule will be activated (0-59).</param> /// <param name="type"></param> public static string Weekly(DayOfWeek dayOfWeek, int hour, int minute, CronType type = CronType.Quartz) { if (type == CronType.Quartz) { return(string.Format("* {0} {1} * * {2}", minute, hour, dayOfWeek)); } return(string.Format("{0} {1} * * {2}", minute, hour, dayOfWeek)); }
public static void UseHangfireTest(this IServiceProvider serviceProvider) { var job = serviceProvider.GetService <HangfireTestJob>(); RecurringJob.AddOrUpdate("定时任务测试", () => job.ExecuteAsync(), CronType.Minute()); //RecurringJob.AddOrUpdate()是定期作业按指定的计划触发任务,同时还有Enqueue、Schedule、ContinueJobWith等等, //可以看一下Hangfire官方文档:https://docs.hangfire.io/en/latest/ }
public void HangfireTwo() { _logger.Information("Log Start..........."); _backgroundJobClient.Enqueue <HangfireService>(x => x.Test("Test Enquence")); _backgroundJobClient.Schedule <HangfireService>(x => x.Test("Schedule Delay one Minutes"), TimeSpan.FromMinutes(1)); _logger.Information("中间商"); RecurringJob.AddOrUpdate("ss", () => Console.WriteLine("Job Id"), CronType.Minute(2)); _logger.Information("Log End .............."); }
public CronJob(string name, long chatId, int narfuGroup, string weatherCity, CronTime time, ConsumerType consumerType, CronType cronType, string text = "") { SetName(name); SetChatId(chatId); SetNarfuGroup(narfuGroup); SetWeatherCity(weatherCity); SetConsumerType(consumerType); SetCronTime(time); SetCronType(cronType); SetText(text); }
/// <summary> /// Get a cron JOB /// </summary> /// <param name="type"></param> /// <returns></returns> public async Task <CronResult> CronGet(CronType type = CronType.PowerOff) { List <object> parameters = new List <object>() { (int)type }; CommandResult <CronResult[]> result = await ExecuteCommandWithResponse <CronResult[]>( method : METHODS.GetCron, parameters : parameters); return(result?.Result?.FirstOrDefault()); }
/// <summary> /// Delete a cron job /// </summary> /// <param name="type"></param> /// <returns></returns> public async Task <bool> CronDelete(CronType type = CronType.PowerOff) { List <object> parameters = new List <object>() { (int)type }; CommandResult <List <string> > result = await ExecuteCommandWithResponse <List <string> >( method : METHODS.DeleteCron, parameters : parameters); return(result.IsOk()); }
/// <summary> /// Add a cron job /// </summary> /// <param name="value"></param> /// <param name="type"></param> /// <returns></returns> public async Task <bool> CronAdd(int value, CronType type = CronType.PowerOff) { List <object> parameters = new List <object>() { (int)type, value }; CommandResult result = await ExecuteCommandWithResponse( method : METHODS.AddCron, id : (int)METHODS.AddCron, parameters : parameters); return(result.IsOk()); }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <returns></returns> public async Task <List <CronJsonResult> > GetCron(CronType type) { var jsonPayload = await SendSettingAndWaitJsonPayload("cron_get", new List <object> { (int)type }); List <CronJsonResult> cronJsonResults = new List <CronJsonResult>(); foreach (string jsonResult in jsonPayload.PayloadParameters.OfType <string>()) { CronJsonResult cronJsonResult = JsonConvert.DeserializeObject <CronJsonResult>(jsonResult); cronJsonResults.Add(cronJsonResult); } return(cronJsonResults); }
public async Task Execute(long chatId, ConsumerType consumerType, CronType cronType, string city, int group, string text) { var sender = _senders.FirstOrDefault(x => x.ConsumerType == consumerType); await Send(responseText => sender.Send(chatId, responseText)); async Task Send(Func <string, Task> func) { if (cronType.HasFlag(CronType.Schedule) && group != 0) { await SendSchedule(chatId, group, func); } if (cronType.HasFlag(CronType.Weather) && !string.IsNullOrWhiteSpace(city)) { await SendWeather(chatId, city, func); } if (cronType.HasFlag(CronType.Text) && !string.IsNullOrWhiteSpace(text)) { await SendText(text, func); } } }
/// <summary> /// Returns cron expression that fires every year on Jan, 1st at 00:00 UTC. /// </summary> /// <param name="type"></param> public static string Yearly(CronType type = CronType.Quartz) { return(Yearly(1, type)); }
/// <summary> /// Returns cron expression that fires every year in the first day at 00:00 UTC /// of the specified month. /// </summary> /// <param name="month">The month in which the schedule will be activated (1-12).</param> /// <param name="type"></param> public static string Yearly(int month, CronType type = CronType.Quartz) { return(Yearly(month, 1, type)); }
/// <summary> /// 小说爬取 /// </summary> /// <param name="context"></param> public static void UseBookJob(this IServiceProvider service) { var job = service.GetService <BookJob>(); RecurringJob.AddOrUpdate("小说爬取", () => job.ExecuteAsync(), CronType.Day(1, 2)); }
/// <summary> /// Returns cron expression that fires every day at 00:00 UTC. /// </summary> /// <param name="type"></param> public static string Daily(CronType type = CronType.Quartz) { return(Daily(0, type)); }
/// <summary> /// Returns cron expression that fires every year at the first minute of the /// specified month, day and hour in UTC. /// </summary> /// <param name="month">The month in which the schedule will be activated (1-12).</param> /// <param name="day">The day of month in which the schedule will be activated (1-31).</param> /// <param name="hour">The hour in which the schedule will be activated (0-23).</param> /// <param name="type"></param> public static string Yearly(int month, int day, int hour, CronType type = CronType.Quartz) { return(Yearly(month, day, hour, 0, type)); }
/// <summary> /// Returns cron expression that fires every hour at the first minute. /// </summary> /// <param name="type"></param> public static string Hourly(CronType type = CronType.Quartz) { return(Hourly(0, type)); }
private void SetCronType(CronType type) { CronType = type; }
/// <summary> /// Returns cron expression that fires every month at the first minute of the /// specified day of month and hour in UTC. /// </summary> /// <param name="day">The day of month in which the schedule will be activated (1-31).</param> /// <param name="hour">The hour in which the schedule will be activated (0-23).</param> /// <param name="type"></param> public static string Monthly(int day, int hour, CronType type = CronType.Quartz) { return(Monthly(day, hour, 0, type)); }
/// <summary> /// Returns cron expression that fires every week at 00:00 UTC of the specified /// day of the week. /// </summary> /// <param name="dayOfWeek">The day of week in which the schedule will be activated.</param> /// <param name="type"></param> public static string Weekly(DayOfWeek dayOfWeek, CronType type = CronType.Quartz) { return(Weekly(dayOfWeek, 0, type)); }
/// <summary> /// 壁纸数据抓取 /// </summary> /// <param name="service"></param> public static void UseWallpaperJob(this IServiceProvider service) { var job = service.GetService <WallpaperJob>(); RecurringJob.AddOrUpdate("壁纸数据抓取", () => job.ExecuteAsync(), CronType.Hour(1, 3)); }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="timerInMinutes"></param> /// <returns></returns> public async Task <bool> AddCron(CronType type, int timerInMinutes) { return(await SendSettingsAndWaitResult("cron_add", new List <object> { (int)type, timerInMinutes })); }
/// <summary> /// 每日热点数据抓取 /// </summary> /// <param name="context"></param> public static void UseHotNewsJob(this IServiceProvider service) { var job = service.GetService <HotNewsJob>(); RecurringJob.AddOrUpdate("每日热点数据抓取", () => job.ExecuteAsync(), CronType.Hour(1, 2)); }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <returns></returns> public async Task <bool> DeleteCron(CronType type) { return(await SendSettingsAndWaitResult("cron_del", new List <object> { })); }
/// <summary> /// Returns cron expression that fires every day at the first minute of /// the specified hour in UTC. /// </summary> /// <param name="hour">The hour in which the schedule will be activated (0-23).</param> /// <param name="type"></param> public static string Daily(int hour, CronType type = CronType.Quartz) { return(Daily(hour, 0, type)); }