예제 #1
0
 protected virtual async Task TryUpdateAsync(IBackgroundJobStore store, BackgroundJobInfo jobInfo)
 {
     try {
         await store.UpdateAsync(jobInfo);
     } catch (Exception updateEx) {
         Logger.LogException(updateEx);
     }
 }
예제 #2
0
        public virtual Task UpdateAsync(BackgroundJobInfo jobInfo)
        {
            if (jobInfo.IsAbandoned)
            {
                return(DeleteAsync(jobInfo.Id));
            }

            return(Task.FromResult(0));
        }
예제 #3
0
        public virtual async Task UpdateAsync(BackgroundJobInfo jobInfo)
        {
            var backgroundJobRecord = await BackgroundJobRepository.FindAsync(jobInfo.Id);

            if (backgroundJobRecord == null)
            {
                return;
            }

            ObjectMapper.Map(jobInfo, backgroundJobRecord);
            await BackgroundJobRepository.UpdateAsync(backgroundJobRecord);
        }
예제 #4
0
        protected virtual DateTime?CalculateNextTryTime(BackgroundJobInfo jobInfo, IClock clock)
        {
            var nextWaitDuration = WorkerOptions.DefaultFirstWaitDuration * (Math.Pow(WorkerOptions.DefaultWaitFactor, jobInfo.TryCount - 1));
            var nextTryDate      = jobInfo.LastTryTime?.AddSeconds(nextWaitDuration) ??
                                   clock.Now.AddSeconds(nextWaitDuration);

            if (nextTryDate.Subtract(jobInfo.CreationTime).TotalSeconds > WorkerOptions.DefaultTimeout)
            {
                return(null);
            }

            return(nextTryDate);
        }
        protected virtual async Task <Guid> EnqueueAsync(string jobName, object args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan?delay = null)
        {
            var jobInfo = new BackgroundJobInfo {
                Id           = GuidGenerator.Create(),
                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);
        }
예제 #6
0
        public virtual Task InsertAsync(BackgroundJobInfo jobInfo)
        {
            _jobs[jobInfo.Id] = jobInfo;

            return(Task.FromResult(0));
        }
예제 #7
0
 public virtual async Task InsertAsync(BackgroundJobInfo jobInfo)
 {
     await BackgroundJobRepository.InsertAsync(
         ObjectMapper.Map <BackgroundJobInfo, BackgroundJobRecord> (jobInfo)
         );
 }