From 20257c24282c9586fe9112275578e496bf6a067b Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 21 Nov 2017 15:48:59 +0000 Subject: [PATCH] Fix build --- src/Ombi.Helpers/Cron.cs | 252 ++++++++++++++++++ src/Ombi.Settings/Ombi.Settings.csproj | 1 - .../Settings/Models/JobSettingsHelper.cs | 3 +- 3 files changed, 253 insertions(+), 3 deletions(-) create mode 100644 src/Ombi.Helpers/Cron.cs diff --git a/src/Ombi.Helpers/Cron.cs b/src/Ombi.Helpers/Cron.cs new file mode 100644 index 000000000..35b141eda --- /dev/null +++ b/src/Ombi.Helpers/Cron.cs @@ -0,0 +1,252 @@ +namespace Ombi.Helpers +{ + // This file is part of Hangfire. + // Copyright © 2013-2014 Sergey Odinokov. + // + // Hangfire is free software: you can redistribute it and/or modify + // it under the terms of the GNU Lesser General Public License as + // published by the Free Software Foundation, either version 3 + // of the License, or any later version. + // + // Hangfire is distributed in the hope that it will be useful, + // but WITHOUT ANY WARRANTY; without even the implied warranty of + // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + // GNU Lesser General Public License for more details. + // + // You should have received a copy of the GNU Lesser General Public + // License along with Hangfire. If not, see . + + using System; + /// + /// Helper class that provides common values for the cron expressions. + /// + public static class Cron + { + /// + /// Returns cron expression that fires every minute. + /// + public static string Minutely() + { + return "* * * * *"; + } + + /// + /// Returns cron expression that fires every hour at the first minute. + /// + public static string Hourly() + { + return Hourly(minute: 0); + } + + /// + /// Returns cron expression that fires every hour at the specified minute. + /// + /// The minute in which the schedule will be activated (0-59). + public static string Hourly(int minute) + { + return $"{minute} * * * *"; + } + + /// + /// Returns cron expression that fires every day at 00:00 UTC. + /// + public static string Daily() + { + return Daily(hour: 0); + } + + /// + /// Returns cron expression that fires every day at the first minute of + /// the specified hour in UTC. + /// + /// The hour in which the schedule will be activated (0-23). + public static string Daily(int hour) + { + return Daily(hour, minute: 0); + } + + /// + /// Returns cron expression that fires every day at the specified hour and minute + /// in UTC. + /// + /// The hour in which the schedule will be activated (0-23). + /// The minute in which the schedule will be activated (0-59). + public static string Daily(int hour, int minute) + { + return $"{minute} {hour} * * *"; + } + + /// + /// Returns cron expression that fires every week at Monday, 00:00 UTC. + /// + public static string Weekly() + { + return Weekly(DayOfWeek.Monday); + } + + /// + /// Returns cron expression that fires every week at 00:00 UTC of the specified + /// day of the week. + /// + /// The day of week in which the schedule will be activated. + public static string Weekly(DayOfWeek dayOfWeek) + { + return Weekly(dayOfWeek, hour: 0); + } + + /// + /// Returns cron expression that fires every week at the first minute + /// of the specified day of week and hour in UTC. + /// + /// The day of week in which the schedule will be activated. + /// The hour in which the schedule will be activated (0-23). + public static string Weekly(DayOfWeek dayOfWeek, int hour) + { + return Weekly(dayOfWeek, hour, minute: 0); + } + + /// + /// Returns cron expression that fires every week at the specified day + /// of week, hour and minute in UTC. + /// + /// The day of week in which the schedule will be activated. + /// The hour in which the schedule will be activated (0-23). + /// The minute in which the schedule will be activated (0-59). + public static string Weekly(DayOfWeek dayOfWeek, int hour, int minute) + { + return $"{minute} {hour} * * {(int)dayOfWeek}"; + } + + /// + /// Returns cron expression that fires every month at 00:00 UTC of the first + /// day of month. + /// + public static string Monthly() + { + return Monthly(day: 1); + } + + /// + /// Returns cron expression that fires every month at 00:00 UTC of the specified + /// day of month. + /// + /// The day of month in which the schedule will be activated (1-31). + public static string Monthly(int day) + { + return Monthly(day, hour: 0); + } + + /// + /// Returns cron expression that fires every month at the first minute of the + /// specified day of month and hour in UTC. + /// + /// The day of month in which the schedule will be activated (1-31). + /// The hour in which the schedule will be activated (0-23). + public static string Monthly(int day, int hour) + { + return Monthly(day, hour, minute: 0); + } + + /// + /// Returns cron expression that fires every month at the specified day of month, + /// hour and minute in UTC. + /// + /// The day of month in which the schedule will be activated (1-31). + /// The hour in which the schedule will be activated (0-23). + /// The minute in which the schedule will be activated (0-59). + public static string Monthly(int day, int hour, int minute) + { + return $"{minute} {hour} {day} * *"; + } + + /// + /// Returns cron expression that fires every year on Jan, 1st at 00:00 UTC. + /// + public static string Yearly() + { + return Yearly(month: 1); + } + + /// + /// Returns cron expression that fires every year in the first day at 00:00 UTC + /// of the specified month. + /// + /// The month in which the schedule will be activated (1-12). + public static string Yearly(int month) + { + return Yearly(month, day: 1); + } + + /// + /// Returns cron expression that fires every year at 00:00 UTC of the specified + /// month and day of month. + /// + /// The month in which the schedule will be activated (1-12). + /// The day of month in which the schedule will be activated (1-31). + public static string Yearly(int month, int day) + { + return Yearly(month, day, hour: 0); + } + + /// + /// Returns cron expression that fires every year at the first minute of the + /// specified month, day and hour in UTC. + /// + /// The month in which the schedule will be activated (1-12). + /// The day of month in which the schedule will be activated (1-31). + /// The hour in which the schedule will be activated (0-23). + public static string Yearly(int month, int day, int hour) + { + return Yearly(month, day, hour, minute: 0); + } + + /// + /// Returns cron expression that fires every year at the specified month, day, + /// hour and minute in UTC. + /// + /// The month in which the schedule will be activated (1-12). + /// The day of month in which the schedule will be activated (1-31). + /// The hour in which the schedule will be activated (0-23). + /// The minute in which the schedule will be activated (0-59). + public static string Yearly(int month, int day, int hour, int minute) + { + return $"{minute} {hour} {day} {month} *"; + } + + /// + /// Returns cron expression that fires every <> minutes. + /// + /// The number of minutes to wait between every activation. + public static string MinuteInterval(int interval) + { + return $"*/{interval} * * * *"; + } + + /// + /// Returns cron expression that fires every <> hours. + /// + /// The number of hours to wait between every activation. + public static string HourInterval(int interval) + { + return $"0 */{interval} * * *"; + } + + /// + /// Returns cron expression that fires every <> days. + /// + /// The number of days to wait between every activation. + public static string DayInterval(int interval) + { + return $"0 0 */{interval} * *"; + } + + /// + /// Returns cron expression that fires every <> months. + /// + /// The number of months to wait between every activation. + public static string MonthInterval(int interval) + { + return $"0 0 1 */{interval} *"; + } + } +} \ No newline at end of file diff --git a/src/Ombi.Settings/Ombi.Settings.csproj b/src/Ombi.Settings/Ombi.Settings.csproj index 9d54dde3e..5a99cc830 100644 --- a/src/Ombi.Settings/Ombi.Settings.csproj +++ b/src/Ombi.Settings/Ombi.Settings.csproj @@ -9,7 +9,6 @@ - diff --git a/src/Ombi.Settings/Settings/Models/JobSettingsHelper.cs b/src/Ombi.Settings/Settings/Models/JobSettingsHelper.cs index 024f79afa..119406baa 100644 --- a/src/Ombi.Settings/Settings/Models/JobSettingsHelper.cs +++ b/src/Ombi.Settings/Settings/Models/JobSettingsHelper.cs @@ -1,5 +1,4 @@ -using Hangfire; -using Ombi.Helpers; +using Ombi.Helpers; namespace Ombi.Settings.Settings.Models {