Ejemplo n.º 1
0
        /// <summary>
        /// Interrupt all instances of the identified InterruptableJob.
        /// </summary>
        public virtual bool Interrupt(JobKey jobKey)
        {
            IList<IJobExecutionContext> jobs = CurrentlyExecutingJobs;

            IJobDetail jobDetail;

            bool interrupted = false;

            foreach (IJobExecutionContext jec in jobs)
            {
                jobDetail = jec.JobDetail;
                if (jobKey.Equals(jobDetail.Key))
                {
                    IJob job = jec.JobInstance;
                    if (job is IInterruptableJob)
                    {
                        ((IInterruptableJob) job).Interrupt();
                        interrupted = true;
                    }
                    else
                    {
                        throw new UnableToInterruptJobException(string.Format(CultureInfo.InvariantCulture, "Job '{0}' can not be interrupted, since it does not implement {1}", jobDetail.Key, typeof(IInterruptableJob).FullName));
                    }
                }
            }

            return interrupted;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Interrupt all instances of the identified InterruptableJob.
        /// </summary>
        public virtual Task<bool> Interrupt(JobKey jobKey)
        {
            var cancellableJobs = CurrentlyExecutingJobs.OfType<ICancellableJobExecutionContext>();

            bool interrupted = false;

            foreach (var cancellableJobExecutionContext in cancellableJobs)
            {
                var jobDetail = cancellableJobExecutionContext.JobDetail;
                if (jobKey.Equals(jobDetail.Key))
                {
                    cancellableJobExecutionContext.Cancel();
                    interrupted = true;
                    break;
                }
            }

            return Task.FromResult(interrupted);
        }