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.
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]);
}
}
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.
How would one go about retrieving a job list in 2.0?
If you want to schedule multiple jobs in your console application you can simply call Scheduler. ScheduleJob (IScheduler) passing the job and the trigger you've previously created: IJobDetail firstJob = JobBuilder. Create<FirstJob>() .
The three primary components in Quartz are jobs, triggers and schedulers, i.e., to create and schedule jobs in Quartz.Net, you would need to have schedulers, triggers and jobs. While a job denotes the task that needs to be executed, a trigger is used to specify how the job will be executed.
Quartz is a job scheduling library that can be integrated into a wide variety of Java applications. Quartz is generally used for enterprise class applications to support process workflow, system management (maintenance) actions and to provide timely services within the applications. Quartz also supports clustering.
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());
}
}
}
}
}
I've used the code found here.
UPDATE:
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.
I've uploaded a sample on github where my main program can receive events of completed jobs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With