public virtual string Enqueue <TJob, TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) where TJob : IBackgroundJobBase <TArgs> { string jobUniqueIdentifier = string.Empty; if (!delay.HasValue) { if (typeof(IBackgroundJob <TArgs>).IsAssignableFrom(typeof(TArgs))) { jobUniqueIdentifier = HangfireBackgroundJob.Enqueue <TJob>(job => ((IBackgroundJob <TArgs>)job).Execute(args)); } else { jobUniqueIdentifier = HangfireBackgroundJob.Enqueue <TJob>(job => ((IAsyncBackgroundJob <TArgs>)job).ExecuteAsync(args)); } } else { if (typeof(IBackgroundJob <TArgs>).IsAssignableFrom(typeof(TArgs))) { jobUniqueIdentifier = HangfireBackgroundJob.Schedule <TJob>(job => ((IBackgroundJob <TArgs>)job).Execute(args), delay.Value); } else { jobUniqueIdentifier = HangfireBackgroundJob.Schedule <TJob>(job => ((IAsyncBackgroundJob <TArgs>)job).ExecuteAsync(args), delay.Value); } } return(jobUniqueIdentifier); }
public Task <bool> DeleteAsync(string jobId) { Throw.IfArgumentNull(jobId, nameof(jobId)); var successfulDeletion = HangfireBackgroundJob.Delete(jobId); return(Task.FromResult(successfulDeletion)); }
public Task <string> EnqueueAsync <TJob, TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) where TJob : IBackgroundJob <TArgs> { var jobUniqueIdentifier = !delay.HasValue ? HangfireBackgroundJob.Enqueue <TJob>(job => job.Execute(args)) : HangfireBackgroundJob.Schedule <TJob>(job => job.Execute(args), delay.Value); return(Task.FromResult(jobUniqueIdentifier)); }
/// <summary> /// 删除一个队列Job /// </summary> /// <param name="jobId"></param> /// <returns></returns> public Task <bool> DeleteAsync(string jobId) { if (string.IsNullOrWhiteSpace(jobId)) { throw new ArgumentNullException(nameof(jobId)); } bool successfulDeletion = HangfireBackgroundJob.Delete(jobId); return(Task.FromResult(successfulDeletion)); }
public virtual bool Delete(string jobId) { if (string.IsNullOrWhiteSpace(jobId)) { throw new ArgumentNullException(nameof(jobId)); } bool successfulDeletion = HangfireBackgroundJob.Delete(jobId); return(successfulDeletion); }
public Task EnqueueAsync <TJob, TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) where TJob : IBackgroundJob <TArgs> { if (!delay.HasValue) { HangfireBackgroundJob.Enqueue <TJob>(job => job.Execute(args)); } else { HangfireBackgroundJob.Schedule <TJob>(job => job.Execute(args), delay.Value); } return(Task.FromResult(0)); }
public virtual string Enqueue <TJob, TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) where TJob : IBackgroundJob <TArgs> { string jobUniqueIdentifier = string.Empty; if (!delay.HasValue) { jobUniqueIdentifier = HangfireBackgroundJob.Enqueue <TJob>(job => job.Execute(args)); } else { jobUniqueIdentifier = HangfireBackgroundJob.Schedule <TJob>(job => job.Execute(args), delay.Value); } return(jobUniqueIdentifier); }
/// <summary> /// 添加一个执行一次的队列Job /// 添加一个定时执行一次的队列Job /// </summary> /// <typeparam name="TJob"></typeparam> /// <typeparam name="TArgs"></typeparam> /// <param name="args"></param> /// <param name="delay"></param> /// <returns></returns> public Task <string> EnqueueAsync <TJob, TArgs>(TArgs args, TimeSpan?delay = null) where TJob : IBackgroundJob <TArgs> { string jobUniqueIdentifier = string.Empty; if (!_hangfireOptions.UseHangfire) { return(Task.FromResult(jobUniqueIdentifier)); } if (!delay.HasValue) { jobUniqueIdentifier = HangfireBackgroundJob.Enqueue <TJob>(job => job.Execute(args)); } else { jobUniqueIdentifier = HangfireBackgroundJob.Schedule <TJob>(job => job.Execute(args), delay.Value); } return(Task.FromResult(jobUniqueIdentifier)); }
public Task EnqueueAsync <TJob, TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) where TJob : IBackgroundJob <TArgs> { HangfireBackgroundJob.Enqueue <TJob>(job => job.Execute(args)); return(Task.FromResult(0)); }