66 lines
2.0 KiB
C#
66 lines
2.0 KiB
C#
using Hangfire;
|
|
using IRaCIS.Core.Application.Service;
|
|
using IRaCIS.Core.Domain.Share;
|
|
using NPOI.SS.Formula.Functions;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace IRaCIS.Core.Application.Helper
|
|
{
|
|
public static class HangfireJobHelper
|
|
{
|
|
|
|
|
|
|
|
//public static void AddOrUpdateCronJob(string jobId, string queueName, Expression<Action> methodCall, string cron)
|
|
//{
|
|
// RecurringJob.AddOrUpdate(jobId, queueName, methodCall, cron);
|
|
//}
|
|
|
|
|
|
|
|
//添加 或者更新定时任务 Id 要唯一标识一个定义任务
|
|
public static void AddOrUpdateCronJob<T>(string jobId, Expression<Action<T>> methodCall, string cron, string queueName="default")
|
|
{
|
|
RecurringJob.AddOrUpdate<T>(jobId, queueName, methodCall, cron);
|
|
}
|
|
|
|
public static void AddOrUpdateInitCronJob<T>(string jobId, Expression<Action<T>> methodCall, string cron)
|
|
{
|
|
RecurringJob.AddOrUpdate<T>(jobId, "sys_init", methodCall, cron);
|
|
}
|
|
|
|
public static void RemoveCronJob(string jobId)
|
|
{
|
|
RecurringJob.RemoveIfExists(jobId);
|
|
}
|
|
|
|
public static void ImmediatelyOnceOnlyJob(Expression<Action> methodCall)
|
|
{
|
|
BackgroundJob.Enqueue("immediately_once", methodCall);
|
|
}
|
|
|
|
public static void ImmediatelyOnceOnlyJob<T>(Expression<Action<T>> methodCall)
|
|
{
|
|
BackgroundJob.Enqueue<T>("immediately_once", methodCall);
|
|
}
|
|
|
|
public static void NotImmediatelyOnceOnlyJob(Expression<Action> methodCall,TimeSpan timeSpan)
|
|
{
|
|
BackgroundJob.Schedule("not_immediately_once", methodCall,timeSpan);
|
|
}
|
|
|
|
public static void NotImmediatelyOnceOnlyJob<T>(Expression<Action<T>> methodCall, TimeSpan timeSpan)
|
|
{
|
|
BackgroundJob.Schedule<T>("not_immediately_once", methodCall, timeSpan);
|
|
}
|
|
|
|
|
|
}
|
|
}
|