public virtual async Task <string> EnqueueAsync <TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) { var jobName = BackgroundJobNameAttribute.GetName <TArgs>(); var jobId = await EnqueueAsync(jobName, args, priority, delay); return(jobId.ToString()); }
/// <summary> /// 后台作业进入周期性队列 /// </summary> /// <typeparam name="TArgs">作业参数类型</typeparam> /// <param name="backgroundJobManager">后台作业管理器</param> /// <param name="cron">Cron表达式</param> /// <param name="args">作业参数</param> /// <returns></returns> public static Task EnqueueAsync <TArgs>( this IBackgroundJobManager backgroundJobManager, [NotNull] string cron, TArgs args ) { Check.NotNullOrWhiteSpace(cron, nameof(cron)); Check.NotNull(args, nameof(args)); var jobName = BackgroundJobNameAttribute.GetName <TArgs>(); RecurringJob.AddOrUpdate <HangfireJobExecutionAdapter <TArgs> >(jobName, adapter => adapter.ExecuteAsync(args), cron); return(Task.CompletedTask); }
public BackgroundJobConfiguration(Type jobType) { JobType = jobType; ArgsType = BackgroundJobArgsHelper.GetJobArgsType(jobType); JobName = BackgroundJobNameAttribute.GetName(ArgsType); }