[英]Get list of background jobs in IQuartzScheduleJobManager
We schedule background jobs in method PostInitialize
of WebModule
like this: 我们在
PostInitialize
的WebModule
方法中安排后台作业,如下所示:
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.