Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cron.cs - MinuteInterval & HourInterval #2141

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions src/Hangfire.Core/Cron.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
// This file is part of Hangfire. Copyright © 2013-2014 Hangfire OÜ.
//
// Hangfire is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
Expand Down Expand Up @@ -114,7 +114,7 @@ public static string Weekly(DayOfWeek dayOfWeek, int hour)
/// <param name="minute">The minute in which the schedule will be activated (0-59).</param>
public static string Weekly(DayOfWeek dayOfWeek, int hour, int minute)
{
return $"{minute} {hour} * * {(int) dayOfWeek}";
return $"{minute} {hour} * * {(int)dayOfWeek}";
}

/// <summary>
Expand Down Expand Up @@ -213,32 +213,40 @@ public static string Yearly(int month, int day, int hour, int minute)
return $"{minute} {hour} {day} {month} *";
}

/// <summary>
/// Returns cron expression that never fires. Specifically 31st of February
/// </summary>
/// <returns></returns>
public static string Never()
{
return Yearly(2, 31);
}
/// <summary>
/// Returns cron expression that never fires. Specifically 31st of February
/// </summary>
/// <returns></returns>
public static string Never()
{
return Yearly(2, 31);
}

/// <summary>
/// Returns cron expression that fires every &lt;<paramref name="interval"></paramref>&gt; minutes.
/// </summary>
/// <param name="interval">The number of minutes to wait between every activation.</param>
[Obsolete("Please use Cron expressions instead. Will be removed in 2.0.0")]
/// <param name="interval">The number of minutes to wait between every activation. Only 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30 values are allowed.</param>
public static string MinuteInterval(int interval)
{
if (interval < 1 || interval > 30 || 60 % interval != 0)
{
throw new ArgumentOutOfRangeException(nameof(interval), "Invalid interval value.");
}

return $"*/{interval} * * * *";
}

/// <summary>
/// Returns cron expression that fires every &lt;<paramref name="interval"></paramref>&gt; hours.
/// </summary>
/// <param name="interval">The number of hours to wait between every activation.</param>
[Obsolete("Please use Cron expressions instead. Will be removed in 2.0.0")]
/// <param name="interval">The number of hours to wait between every activation. Only 1, 2, 3, 4, 6, 8, 12 value are allowed.</param>
public static string HourInterval(int interval)
{
if (interval < 1 || interval > 12 || 24 % interval != 0)
{
throw new ArgumentOutOfRangeException(nameof(interval), "Invalid interval value.");
}

return $"0 */{interval} * * *";
}

Expand Down