简体   繁体   English

在IQuartzScheduleJobManager中获取后台作业列表

[英]Get list of background jobs in IQuartzScheduleJobManager

We schedule background jobs in method PostInitialize of WebModule like this: 我们在PostInitializeWebModule方法中安排后台作业,如下所示:

IocManager.Resolve<IQuartzScheduleJobManager>().ScheduleAsync<WorkFlowDetailNotificationWorker>(job =>
{
    job.WithIdentity("SendNotificationForRemainGardeshKarDetail", "AutoNotification")
       .WithDescription("WorkFlowsNotification");
}, trigger =>
{
    trigger.StartNow().WithSchedule(CronScheduleBuilder.CronSchedule("0 0/60 8-19 * * ?")).Build();
});

How can we get the list of registered background jobs in Application Service, so that we can manipulate their properties? 我们如何获得Application Service中已注册的后台作业的列表,以便我们可以操纵它们的属性?

Our project startup template is ASP.NET Boilerplate, AngularJS and EntityFramework. 我们的项目启动模板是ASP.NET Boilerplate,AngularJS和EntityFramework。

You can get list of all the jobs registered to Quartz in Asp.Net Boilerplate framework like below; 您可以在Asp.Net Boilerplate框架中获得注册到Quartz的所有作业的列表,如下所示;

    public class MySampleAppService
    {
            private readonly IAbpQuartzConfiguration _abpQuartzConfiguration;

            public MySampleAppService(IAbpQuartzConfiguration abpQuartzConfiguration)
            {
               _abpQuartzConfiguration = abpQuartzConfiguration
            }

            private void ListAllJobs()
            {
                var scheduler = _abpQuartzConfiguration.Scheduler;
                var jobGroups = scheduler.GetJobGroupNames();
                foreach (string group in jobGroups)
                {
                    var groupMatcher = GroupMatcher<JobKey>.GroupContains(group);
                    var jobKeys = scheduler.GetJobKeys(groupMatcher);
                    foreach (var jobKey in jobKeys)
                    {
                        var detail = scheduler.GetJobDetail(jobKey);
                        var triggers = scheduler.GetTriggersOfJob(jobKey);
                        foreach (ITrigger trigger in triggers)
                        {
                            Console.WriteLine(group);
                            Console.WriteLine(jobKey.Name);
                            Console.WriteLine(detail.Description);
                            Console.WriteLine(trigger.Key.Name);
                            Console.WriteLine(trigger.Key.Group);
                            Console.WriteLine(trigger.GetType().Name);
                            Console.WriteLine(scheduler.GetTriggerState(trigger.Key));

                            var nextFireTime = trigger.GetNextFireTimeUtc();
                            if (nextFireTime.HasValue)
                            {
                                Console.WriteLine(nextFireTime.Value.LocalDateTime.ToString(CultureInfo.InvariantCulture));
                            }

                            var previousFireTime = trigger.GetPreviousFireTimeUtc();
                            if (previousFireTime.HasValue)
                            {
                                Console.WriteLine(previousFireTime.Value.LocalDateTime.ToString(CultureInfo.InvariantCulture));
                            }
                        }
                    }
                }
            }

      //...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hangfire .NET Core - 获取排队的作业列表 - Hangfire .NET Core - Get enqueued jobs list 获取背景窗口列表。 - Get list of background windows. 如何在 C# 中使用 JobStorage 获取所有 Hangfire 作业的列表? - How to get List of all Hangfire Jobs using JobStorage in C#? 未注册的服务“ Abp.Quartz.IQuartzScheduleJobManager” - Service 'Abp.Quartz.IQuartzScheduleJobManager' which was not registered 如何在 C# 中使用 REST API 获取 Azure 批处理池和作业列表? - How to get list of Azure Batch Pools and Jobs using REST API in C#? Teams 频道中 Microsoft Bot Framework 中的后台作业 - Background jobs in Microsoft Bot Framework in Teams Channel 在 Parallel.foreach 中取消后台运行作业 - Cancel background running jobs in Parallel.foreach 试图获取列表框以更改表单C#的背景色 - Trying to get the list box to change the background color of the form c# 针对多个线程的“剪切”排序作业列表 - “Shear” sort list of jobs for multiple threads efficiently 是否可以一项一项地运行我的作业(基于 Scoped Background Services)? - Is it possible to run my jobs (that are based on Scoped Background Services) one by one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM