/// <summary> /// Enqueues a job to be executed. /// </summary> /// <typeparam name="TJob">Type of the job.</typeparam> /// <typeparam name="TArgs">Type of the arguments of job.</typeparam> /// <param name="backgroundJobManager">Background job manager reference</param> /// <param name="args">Job arguments.</param> /// <param name="priority">Job priority.</param> /// <param name="delay">Job delay (wait duration before first try).</param> public static void Enqueue <TJob, TArgs>(this IBackgroundJobManager backgroundJobManager, TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) where TJob : IBackgroundJob <TArgs> { AsyncHelper.RunSync(() => backgroundJobManager.EnqueueAsync <TJob, TArgs>(args, priority, delay)); }
/// <summary> /// Initializes a new instance of the <see cref="BackgroundJobInfo"/> class. /// </summary> public BackgroundJobInfo() { NextTryTime = Clock.Now; Priority = BackgroundJobPriority.Normal; }
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)); }
public static Task EnqueueEventAsync <TEvent>(this IBackgroundJobManager backgroundJobManager, TEvent e, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) where TEvent : EventData { return(backgroundJobManager.EnqueueAsync <EventTriggerAsyncBackgroundJob <TEvent>, TEvent>(e, priority, delay)); }
/// <summary> /// Initializes a new instance of the <see cref="BackgroundJobInfo"/> class. /// </summary> public BackgroundJobInfo() { NextTryTime = DateTime.Now; CreationTime = DateTime.Now; Priority = BackgroundJobPriority.Normal; }
/// <summary> /// Enqueues a job to be executed. /// </summary> /// <typeparam name="TArgs">Type of the arguments of job.</typeparam> /// <param name="backgroundJobManager">Background job manager reference</param> /// <param name="args">Job arguments.</param> /// <param name="priority">Job priority.</param> /// <param name="delay">Job delay (wait duration before first try).</param> public static string Enqueue <TArgs>(this IBackgroundJobManager backgroundJobManager, TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) { return(AsyncHelper.RunSync(() => backgroundJobManager.EnqueueAsync <TArgs>(args, priority, delay))); }
public virtual async Task <string> EnqueueAsync <TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) { return(await ReEnqueueAsync(args, Options.RetryCount, Options.RetryIntervalMillisecond, priority, delay)); }
protected override async Task <Guid> EnqueueAsync(string jobName, object args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) { var id = GuidGenerator.Create(); if (args is BackgroundJobArgs) { (args as BackgroundJobArgs).Id = id; } var jobInfo = new BackgroundJobInfo { Id = id, JobName = jobName, JobArgs = Serializer.Serialize(args), Priority = priority, CreationTime = Clock.Now, NextTryTime = Clock.Now }; if (delay.HasValue) { jobInfo.NextTryTime = Clock.Now.Add(delay.Value); } await Store.InsertAsync(jobInfo); return(jobInfo.Id); }
/// <summary> /// /// </summary> /// <param name="jobName"></param> /// <param name="args"></param> /// <param name="priority"></param> /// <param name="delay"></param> /// <returns></returns> protected virtual async Task <Guid> EnqueueAsync(string jobName, object args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) { var jobInfo = new BackgroundJobInfo { Id = Guid.NewGuid(), JobName = jobName, JobArgs = Serializer.Serialize(args), Priority = priority, CreationTime = Clock.Now, NextTryTime = Clock.Now }; if (delay.HasValue) { jobInfo.NextTryTime = Clock.Now.Add(delay.Value); } await Store.InsertAsync(jobInfo); return(jobInfo.Id); }
/// <summary> /// Initializes a new instance of the <see cref="BackgroundJobInfo"/> class. /// </summary> public BackgroundJobInfo() { Priority = BackgroundJobPriority.Normal; }
public virtual Task <string> EnqueueAsync <TArgs> (TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) { throw new RocketException("Background job system has not a real implementation. If it's mandatory, use an implementation (either the default provider or a 3rd party implementation). If it's optional, check IBackgroundJobManager.IsAvailable() extension method and act based on it."); }
public async Task <LongRunResult> EnqueueLongRunAsync <TJob, TArgs>(TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null) where TJob : LongRunBackgroundJob <TArgs> { LongRunInfo longRunInfo; string longRunId; // i removed try catches for persisting. // let it be handled by unit of work and thorwing exceptions using (var unitOfWork = UnitOfWorkManager.Begin()) { longRunId = _keyGenerator.Generate <string>(); longRunInfo = new LongRunInfo { Id = longRunId, //todo: serializer? or json repo? Args = JsonConvert.SerializeObject(args), LongRunStatus = LongRunStatus.Queued, Type = typeof(TJob).ToString(), }; await _longRunInfoRepo.InsertAsync(longRunInfo); await unitOfWork.CompleteAsync(); } string jobId; try { // try to queue job var longRunArgs = new LongRunArgs <TArgs> { Args = args, LongRunInfoId = longRunId }; jobId = await EnqueueAsync <TJob, LongRunArgs <TArgs> >(longRunArgs, priority, delay); } catch (Exception e) { try { using (var unitOfWork = UnitOfWorkManager.Begin()) { longRunInfo = await _longRunInfoRepo.GetAsync(longRunInfo.Id); longRunInfo.LongRunStatus = LongRunStatus.QueueFailed; longRunInfo.Error = e.ToString(); await unitOfWork.CompleteAsync(); } } catch (Exception) { //todo: additional handler? } throw; } try { using (var unitOfWork = UnitOfWorkManager.Begin()) { longRunInfo = await _longRunInfoRepo.GetAsync(longRunInfo.Id); longRunInfo.JobId = jobId; await unitOfWork.CompleteAsync(); } } catch (Exception) { //todo: additional handler? } return(new LongRunResult { LongRunId = longRunId, JobId = jobId }); }
public Task <int> AddOrUpdateAsync <TJob, TArgs>(string recurringJobId, TArgs args, string cronExpressions, string timeZoneId, BackgroundJobPriority priority = BackgroundJobPriority.Normal) where TJob : IBackgroundJob <TArgs> { RecurringJob.AddOrUpdate <TJob>(recurringJobId, job => job.Execute(args), cronExpressions, TimeZoneInfo.FindSystemTimeZoneById(timeZoneId)); return(Task.FromResult(0)); }