简体   繁体   English

无法在Quartz Scheduler中获取作业列表

[英]Unable to get Listing of Jobs in the Quartz Scheduler

I am trying to fetch all jobs registered with the Quartz scheduler for a particular group. 我正在尝试获取在Quartz调度程序中为特定组注册的所有作业。 here is my piece of code 这是我的一段代码

CustomSchdularFactory.getSchedulerInstance().getJobKeys(groupEquals(group));

here group is a String variable holding the name of group whose associated jobs i want to fetch. 这里的group是一个String变量,包含我想要获取的关联作业的组名。 while using the above code i am getting following error 使用上面的代码我得到以下错误

The method getJobKeys(GroupMatcher<JobKey>) in the type Scheduler is not applicable for the arguments (GroupMatcher<Key<Key<T>>>)

i am not sure why this error is occurring as i took the reference from Quartz official documents 我不确定为什么会出现这个错误,因为我从Quartz官方文档中获取了参考

ListJobs ListJobs

Use jobGroupEquals instead of groupEquals 使用jobGroupEquals而不是groupEquals

CustomSchdularFactory.getSchedulerInstance().getJobKeys(jobGroupEquals(group));

and it will work for you. 它会对你有用。

Use it 用它

Scheduler sched = new StdSchedulerFactory().getScheduler();

for(String group: sched.getJobGroupNames()) {
   for(JobKey jobKey : sched.getJobKeys(GroupMatcher.jobGroupEquals(group))) {
      ...
   }
}

On Quartz.NET 3.0, I was able to get this working in asynchronous mode: 在Quartz.NET 3.0上,我能够在异步模式下工作:

public static async Task RunTask() {
    StdSchedulerFactory factory = new StdSchedulerFactory(System.Configuration.ConfigurationManager.AppSettings);
    IScheduler scheduler = await factory.GetScheduler();
    await scheduler.Start();

    IReadOnlyCollection<string> jgn = await sch.GetJobGroupNames(new System.Threading.CancellationToken());
    foreach (string jno in jgn)
    {
        IReadOnlyCollection <JobKey> jk = await sch.GetJobKeys(jobGroupEquals(jno));
        foreach (JobKey j in jk)
        {
            var currentJob = await sch.GetJobDetail(j);

            //print the properties of the current job
            Console.WriteLine(currentJob.Key.Name);
            Console.WriteLine(currentJob.Description);
        }                   
    }
}   

private static GroupMatcher<JobKey> jobGroupEquals(string jno)
{
    return GroupMatcher<JobKey>.GroupEquals(jno);
}

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

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