简体   繁体   中英

Get list of background jobs in IQuartzScheduleJobManager

We schedule background jobs in method PostInitialize of WebModule like this:

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?

Our project startup template is ASP.NET Boilerplate, AngularJS and EntityFramework.

You can get list of all the jobs registered to Quartz in Asp.Net Boilerplate framework like below;

    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));
                            }
                        }
                    }
                }
            }

      //...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM