获取所有作业Quartz.NET 2.0 [英] Get all jobs in Quartz.NET 2.0

查看:654
本文介绍了获取所有作业Quartz.NET 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在服务器上设置我的AdoJobStore和我所有的工作都运行完美。现在我写一个远程客户端来管理我的所有作业。

I've setup my AdoJobStore on the server and all my jobs are running perfectly. Now I am writing a remote client to manage all my jobs.

调度新的就业机会是简单明了的,但我似乎无法在2.0版来获取现有作业的列表。所有我发现的资源做了一件像下面这样。

Scheduling new jobs is straightforward enough, but I can't seem to retrieve a list of existing jobs in version 2.0. All the resources I found did something like the following.

var groups = sched.JobGroupNames;
for (int i = 0; i < groups.Length; i++)
{
    string[] names = sched.GetJobNames(groups[i]);
    for (int j = 0; j < names.Length; j++)
    {
        var currentJob = sched.GetJobDetail(names[j], groups[i]);
    }
}

我现在面临的问题是,GetJobNames已被删除,并查看源$ C ​​$ C,已被移动到了基类JobStoreSupport,这JobStoreCMS从继承。该方法已然而被标记为受保护的,所以它是从外部访问。

The problem I'm facing is that GetJobNames has been removed, and looking at the source code, has been moved to the base class JobStoreSupport, which JobStoreCMS inherits from. The method has however been marked as protected, so it is inaccessible from the outside.

如何将一个去2.0检索作业列表?

How would one go about retrieving a job list in 2.0?

推荐答案

您可以用获取执行作业的列表:

You can use fetch a list of executing jobs:

var executingJobs = sched.GetCurrentlyExecutingJobs();
foreach (var job in executingJobs)
{
    // Console.WriteLine(job.JobDetail.Key);
}

或抓取所有关于调度作业信息(示例控制台应用程序):

or fetch all the info about scheduled jobs (sample console application):

private static void GetAllJobs(IScheduler scheduler)
{
    IList<string> jobGroups = scheduler.GetJobGroupNames();
    // IList<string> triggerGroups = scheduler.GetTriggerGroupNames();

    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));
                DateTimeOffset? nextFireTime = trigger.GetNextFireTimeUtc();
                if (nextFireTime.HasValue)
                {
                    Console.WriteLine(nextFireTime.Value.LocalDateTime.ToString());
                }

                DateTimeOffset? previousFireTime = trigger.GetPreviousFireTimeUtc();
                if (previousFireTime.HasValue)
                {
                    Console.WriteLine(previousFireTime.Value.LocalDateTime.ToString());
                }
            }
        }
    } 
}

我用code发现<一个href=\"https://github.com/adometry/QuartzNetManager/blob/master/ClickForensics.Quartz.Manager/QuartzScheduler.cs\"相对=nofollow>这里。

I've used the code found here.

更新

如果有人有兴趣的样本code可以从我的GitHub 下载。

If someone is interested a sample code can be downloaded from my GitHub repository.

有人问如何让工作完成的清单。结果
我不认为有对于一个简单的方法。结果
该想到的唯一选择是使用工作(或触发)侦听器。

Someone asked how to get a list of job completed.
I don't think there's an easy way for that.
The only option which comes to mind is using a job (or trigger) listener.

我上传GitHub上一个样品在我的主程序可以收到完成的作业的事件。

I've uploaded a sample on github where my main program can receive events of completed jobs.

这篇关于获取所有作业Quartz.NET 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆