110 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			110 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			C#
		
	
	
| using Hangfire;
 | |
| using IRaCIS.Core.Application.MassTransit.Consumer;
 | |
| using IRaCIS.Core.Domain.Share;
 | |
| using MassTransit.Mediator;
 | |
| 
 | |
| 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, new RecurringJobOptions() { TimeZone = TimeZoneInfo.Local });
 | |
|         }
 | |
| 
 | |
|         public static void AddOrUpdateInitCronJob<T>(string jobId, Expression<Action<T>> methodCall, string cron)
 | |
|         {
 | |
|             RecurringJob.AddOrUpdate<T>(jobId, "sys_init", methodCall, cron, new RecurringJobOptions() { TimeZone = TimeZoneInfo.Local });
 | |
|         }
 | |
| 
 | |
|         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);
 | |
|         }
 | |
| 
 | |
| 
 | |
|         public static void AddOrUpdateTrialCronJob(string jobId, Guid trialId, EmailBusinessScenario businessScenario, string emailCron)
 | |
|         {
 | |
| 
 | |
|             switch (businessScenario)
 | |
|             {
 | |
| 
 | |
|                 case EmailBusinessScenario.QCTask:
 | |
| 
 | |
|                     HangfireJobHelper.AddOrUpdateCronJob<IMediator>(jobId, t => t.Send(new ImageQCRecurringEvent() { TrialId = trialId }, default), emailCron);
 | |
|                     break;
 | |
|                 case EmailBusinessScenario.CRCToQCQuestion:
 | |
|                     HangfireJobHelper.AddOrUpdateCronJob<IMediator>(jobId, t => t.Send(new CRCImageQuestionRecurringEvent() { TrialId = trialId }, default), emailCron);
 | |
|                     break;
 | |
|                 case EmailBusinessScenario.QCToCRCImageQuestion:
 | |
|                     HangfireJobHelper.AddOrUpdateCronJob<IMediator>(jobId, t => t.Send(new QCImageQuestionRecurringEvent() { TrialId = trialId }, default), emailCron);
 | |
|                     break;
 | |
|                 //加急阅片 10分钟
 | |
|                 case EmailBusinessScenario.ExpeditedReading:
 | |
|                     HangfireJobHelper.AddOrUpdateCronJob<IMediator>(jobId, t => t.Send(new UrgentIRUnReadTaskRecurringEvent() { TrialId = trialId }, default), emailCron);
 | |
|                     break;
 | |
|                 default:
 | |
|                     break;
 | |
|             }
 | |
| 
 | |
|         }
 | |
| 
 | |
|         public static void AddOrUpdateTimingCronJob(string jobId, EmailBusinessScenario businessScenario, string emailCron)
 | |
|         {
 | |
|             switch (businessScenario)
 | |
|             {
 | |
| 
 | |
|                 case EmailBusinessScenario.GeneralTraining_ExpirationNotification:
 | |
| 
 | |
| 
 | |
|                     HangfireJobHelper.AddOrUpdateCronJob<IMediator>(jobId, t => t.Send(new SystemDocumentErverDayEvent() { }, default), emailCron);
 | |
|                     break;
 | |
|                 case EmailBusinessScenario.TrialTraining_ExpirationNotification:
 | |
| 
 | |
|                     Console.WriteLine("更新项目到期job");
 | |
|                     HangfireJobHelper.AddOrUpdateCronJob<IMediator>(jobId, t => t.Send(new TrialDocumentErverDayEvent() { }, default), emailCron);
 | |
|                     break;
 | |
| 
 | |
|                 default:
 | |
|                     break;
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 | |
| 
 |