Testing for IInterruptableJob

2020-04-20 21:11发布

问题:

I have the following code:

    private static void InterruptAJob(JobKey foundJobKey, IScheduler sched)
    {
        if (null != foundJobKey)
        {
            sched.Interrupt(foundJobKey);
        }
    }

I get this exception (I expect this):

"Job 'groupName001.testJobDetailImpl_0' can not be interrupted, since it does not implement Quartz.IInterruptableJob"

Is there a way to test for IInterruptableJob using the "JobKey"?

........

EDIT (APPEND)

/// <summary>
/// Request the interruption, within this Scheduler instance, of all
/// currently executing instances of the identified <see cref="IJob" />, which
/// must be an implementor of the <see cref="IInterruptableJob"/> interface.
/// </summary>
/// <remarks>
/// <para>
/// If more than one instance of the identified job is currently executing,
/// the <see cref="IInterruptableJob.Interrupt"/> method will be called on
/// each instance. However, there is a limitation that in the case that
/// <see cref="Interrupt(JobKey)"/> on one instances throws an exception, all
/// remaining instances (that have not yet been interrupted) will not have
/// their <see cref="Interrupt(JobKey)"/> method called.
/// </para>
/// <para>
/// If you wish to interrupt a specific instance of a job (when more than
/// one is executing) you can do so by calling
/// <see cref="GetCurrentlyExecutingJobs"/> to obtain a handle
/// to the job instance, and then invoke <see cref="Interrupt(JobKey)"/> on it
/// yourself.
/// </para>
/// <para>
/// This method is not cluster aware. That is, it will only interrupt
/// instances of the identified InterruptableJob currently executing in this
/// Scheduler instance, not across the entire cluster.
/// </para>
/// </remarks>
/// <returns>true is at least one instance of the identified job was found and interrupted.</returns>
/// <throws> UnableToInterruptJobException if the job does not implement </throws>
/// <seealso cref="IInterruptableJob"/>
/// <seealso cref="GetCurrentlyExecutingJobs"/>
public virtual bool Interrupt(JobKey jobKey)
{

The comments say use IScheduler.GetCurrentlyExecutingJobs(). Which gives me a collection of JobKey's.

I guess another way to ask the question is... how I can get this below functionality?

IScheduler.GetCurrentlyExecutingIInterruptableJobs

标签: c# quartz.net