Last active
July 22, 2019 09:02
-
-
Save odinserj/5e76c60b4f80bcc48d0f921e6a9105eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq.Expressions; | |
using Hangfire.Annotations; | |
using Hangfire.Common; | |
using Hangfire.States; | |
namespace Hangfire | |
{ | |
public static class RecurringJobManagerExtensions | |
{ | |
public static void AddOrUpdate( | |
[NotNull] this RecurringJobManager manager, | |
[NotNull] string recurringJobId, | |
[NotNull] Expression<Action> methodCall, | |
[NotNull] Func<string> cronExpression, | |
TimeZoneInfo timeZone = null, | |
string queue = EnqueuedState.DefaultQueue) | |
{ | |
if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); | |
AddOrUpdate(manager, recurringJobId, methodCall, cronExpression(), timeZone, queue); | |
} | |
public static void AddOrUpdate<T>( | |
[NotNull] this RecurringJobManager manager, | |
[NotNull] string recurringJobId, | |
[NotNull] Expression<Action<T>> methodCall, | |
[NotNull] Func<string> cronExpression, | |
TimeZoneInfo timeZone = null, | |
string queue = EnqueuedState.DefaultQueue) | |
{ | |
if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); | |
AddOrUpdate(manager, recurringJobId, methodCall, cronExpression(), timeZone, queue); | |
} | |
public static void AddOrUpdate( | |
[NotNull] this RecurringJobManager manager, | |
[NotNull] string recurringJobId, | |
[NotNull] Expression<Action> methodCall, | |
[NotNull] string cronExpression, | |
TimeZoneInfo timeZone = null, | |
string queue = EnqueuedState.DefaultQueue) | |
{ | |
if (manager == null) throw new ArgumentNullException(nameof(manager)); | |
if (recurringJobId == null) throw new ArgumentNullException(nameof(recurringJobId)); | |
if (methodCall == null) throw new ArgumentNullException(nameof(methodCall)); | |
if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); | |
var job = Job.FromExpression(methodCall); | |
manager.AddOrUpdate(recurringJobId, job, cronExpression, timeZone ?? TimeZoneInfo.Utc, queue); | |
} | |
public static void AddOrUpdate<T>( | |
[NotNull] this RecurringJobManager manager, | |
[NotNull] string recurringJobId, | |
[NotNull] Expression<Action<T>> methodCall, | |
[NotNull] string cronExpression, | |
TimeZoneInfo timeZone = null, | |
string queue = EnqueuedState.DefaultQueue) | |
{ | |
if (manager == null) throw new ArgumentNullException(nameof(manager)); | |
if (recurringJobId == null) throw new ArgumentNullException(nameof(recurringJobId)); | |
if (methodCall == null) throw new ArgumentNullException(nameof(methodCall)); | |
if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); | |
var job = Job.FromExpression(methodCall); | |
manager.AddOrUpdate(recurringJobId, job, cronExpression, timeZone ?? TimeZoneInfo.Utc, queue); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq.Expressions; | |
using System.Threading.Tasks; | |
using Hangfire.Annotations; | |
using Hangfire.Common; | |
using Hangfire.States; | |
namespace Hangfire | |
{ | |
public static class RecurringJobManagerExtensions | |
{ | |
public static void AddOrUpdate( | |
[NotNull] this IRecurringJobManager manager, | |
[NotNull] string recurringJobId, | |
[NotNull] Expression<Action> methodCall, | |
[NotNull] Func<string> cronExpression, | |
TimeZoneInfo timeZone = null, | |
string queue = EnqueuedState.DefaultQueue) | |
{ | |
if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); | |
AddOrUpdate(manager, recurringJobId, methodCall, cronExpression(), timeZone, queue); | |
} | |
public static void AddOrUpdate<T>( | |
[NotNull] this IRecurringJobManager manager, | |
[NotNull] string recurringJobId, | |
[NotNull] Expression<Action<T>> methodCall, | |
[NotNull] Func<string> cronExpression, | |
TimeZoneInfo timeZone = null, | |
string queue = EnqueuedState.DefaultQueue) | |
{ | |
if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); | |
AddOrUpdate(manager, recurringJobId, methodCall, cronExpression(), timeZone, queue); | |
} | |
public static void AddOrUpdate( | |
[NotNull] this IRecurringJobManager manager, | |
[NotNull] string recurringJobId, | |
[NotNull] Expression<Action> methodCall, | |
[NotNull] string cronExpression, | |
TimeZoneInfo timeZone = null, | |
string queue = EnqueuedState.DefaultQueue) | |
{ | |
if (manager == null) throw new ArgumentNullException(nameof(manager)); | |
if (recurringJobId == null) throw new ArgumentNullException(nameof(recurringJobId)); | |
if (methodCall == null) throw new ArgumentNullException(nameof(methodCall)); | |
if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); | |
var job = Job.FromExpression(methodCall); | |
manager.AddOrUpdate(recurringJobId, job, cronExpression, timeZone ?? TimeZoneInfo.Utc, queue); | |
} | |
public static void AddOrUpdate<T>( | |
[NotNull] this IRecurringJobManager manager, | |
[NotNull] string recurringJobId, | |
[NotNull] Expression<Action<T>> methodCall, | |
[NotNull] string cronExpression, | |
TimeZoneInfo timeZone = null, | |
string queue = EnqueuedState.DefaultQueue) | |
{ | |
if (manager == null) throw new ArgumentNullException(nameof(manager)); | |
if (recurringJobId == null) throw new ArgumentNullException(nameof(recurringJobId)); | |
if (methodCall == null) throw new ArgumentNullException(nameof(methodCall)); | |
if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); | |
var job = Job.FromExpression(methodCall); | |
manager.AddOrUpdate(recurringJobId, job, cronExpression, timeZone ?? TimeZoneInfo.Utc, queue); | |
} | |
public static void AddOrUpdate( | |
[NotNull] this IRecurringJobManager manager, | |
[NotNull] string recurringJobId, | |
[NotNull] Expression<Func<Task>> methodCall, | |
[NotNull] Func<string> cronExpression, | |
TimeZoneInfo timeZone = null, | |
string queue = EnqueuedState.DefaultQueue) | |
{ | |
if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); | |
AddOrUpdate(manager, recurringJobId, methodCall, cronExpression(), timeZone, queue); | |
} | |
public static void AddOrUpdate<T>( | |
[NotNull] this IRecurringJobManager manager, | |
[NotNull] string recurringJobId, | |
[NotNull] Expression<Func<T, Task>> methodCall, | |
[NotNull] Func<string> cronExpression, | |
TimeZoneInfo timeZone = null, | |
string queue = EnqueuedState.DefaultQueue) | |
{ | |
if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); | |
AddOrUpdate(manager, recurringJobId, methodCall, cronExpression(), timeZone, queue); | |
} | |
public static void AddOrUpdate( | |
[NotNull] this IRecurringJobManager manager, | |
[NotNull] string recurringJobId, | |
[NotNull] Expression<Func<Task>> methodCall, | |
[NotNull] string cronExpression, | |
TimeZoneInfo timeZone = null, | |
string queue = EnqueuedState.DefaultQueue) | |
{ | |
if (manager == null) throw new ArgumentNullException(nameof(manager)); | |
if (recurringJobId == null) throw new ArgumentNullException(nameof(recurringJobId)); | |
if (methodCall == null) throw new ArgumentNullException(nameof(methodCall)); | |
if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); | |
var job = Job.FromExpression(methodCall); | |
manager.AddOrUpdate(recurringJobId, job, cronExpression, timeZone ?? TimeZoneInfo.Utc, queue); | |
} | |
public static void AddOrUpdate<T>( | |
[NotNull] this IRecurringJobManager manager, | |
[NotNull] string recurringJobId, | |
[NotNull] Expression<Func<T, Task>> methodCall, | |
[NotNull] string cronExpression, | |
TimeZoneInfo timeZone = null, | |
string queue = EnqueuedState.DefaultQueue) | |
{ | |
if (manager == null) throw new ArgumentNullException(nameof(manager)); | |
if (recurringJobId == null) throw new ArgumentNullException(nameof(recurringJobId)); | |
if (methodCall == null) throw new ArgumentNullException(nameof(methodCall)); | |
if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); | |
var job = Job.FromExpression(methodCall); | |
manager.AddOrUpdate(recurringJobId, job, cronExpression, timeZone ?? TimeZoneInfo.Utc, queue); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment