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());
    }
        public async Task <List <JobHistory> > ListJobHistoryAsync <TJobArgs>()
        {
            var jobName        = JsonSerializer.Serialize(BackgroundJobNameAttribute.GetName <TJobArgs>());
            var entityFullName = typeof(Volo.Abp.BackgroundJobs.BackgroundJobRecord).FullName;
            var query          = DbContext.Set <EntityChange>().AsNoTracking()
                                 .Where(x => x.EntityTypeFullName == entityFullName.TruncateFromBeginning(EntityChangeConsts.MaxEntityTypeFullNameLength))
                                 .Where(x => x.ChangeType == Volo.Abp.Auditing.EntityChangeType.Created)
                                 .Where(x => x.PropertyChanges.Any(y => y.PropertyName == nameof(BackgroundJobRecord.JobName) && y.NewValue == jobName))
                                 .Select(x => x.EntityId)
                                 .Distinct();
            var list = DbContext.Set <EntityChange>().AsNoTracking()
                       .Where(x => query.Contains(x.EntityId));
            var result = await list.GroupBy(x => x.EntityId)
                         .Select(x => new JobHistory
            {
                JobId            = x.Key,
                JobName          = jobName,
                ExecuteStartTime = x.Min(y => y.ChangeTime),
                ExecuteEndTime   = x.Max(y => y.ChangeTime),
                ProgressCount    = x.Count(),
                IsFinish         = x.Max(p => p.ChangeType) == Volo.Abp.Auditing.EntityChangeType.Deleted
            }).ToListAsync();

            return(result);
        }
        /// <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.Execute(args), cron);

            return(Task.CompletedTask);
        }
Beispiel #4
0
 public BackgroundJobConfiguration(Type jobType)
 {
     JobType  = jobType;
     ArgsType = BackgroundJobArgsHelper.GetJobArgsType(jobType);
     JobName  = BackgroundJobNameAttribute.GetName(ArgsType);
 }