/// <summary> /// Called by the scheduler at the time of the trigger firing, in order to /// produce a <see cref="T:Quartz.IJob" /> instance on which to call Execute. /// </summary> /// <remarks> /// It should be extremely rare for this method to throw an exception - /// basically only the the case where there is no way at all to instantiate /// and prepare the Job for execution. When the exception is thrown, the /// Scheduler will move all triggers associated with the Job into the /// <see cref="F:Quartz.TriggerState.Error" /> state, which will require human /// intervention (e.g. an application restart after fixing whatever /// configuration problem led to the issue wih instantiating the Job. /// </remarks> /// <param name="bundle"> /// The TriggerFiredBundle from which the <see cref="T:Quartz.IJobDetail" /> /// and other info relating to the trigger firing can be obtained. /// </param> /// <param name="scheduler">a handle to the scheduler that is about to execute the job</param> /// <throws>SchedulerException if there is a problem instantiating the Job. </throws> /// <returns> /// the newly instantiated Job /// </returns> public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { if (bundle == null) throw new ArgumentNullException("bundle"); if (scheduler == null) throw new ArgumentNullException("scheduler"); var jobType = bundle.JobDetail.JobType; return jobType.IsAssignableTo<IInterruptableJob>() ? new InterruptableJobWrapper(bundle, _lifetimeScope, _scopeName) : new JobWrapper(bundle, _lifetimeScope, _scopeName); }
/// <summary> /// Called by the scheduler at the time of the trigger firing, in order to /// produce a <see cref="T:Quartz.IJob" /> instance on which to call Execute. /// </summary> /// <param name="bundle">The TriggerFiredBundle from which the <see cref="T:Quartz.IJobDetail" /> /// and other info relating to the trigger firing can be obtained.</param> /// <param name="scheduler">a handle to the scheduler that is about to execute the job</param> /// <returns> /// the newly instantiated Job /// </returns> /// <throws> SchedulerException if there is a problem instantiating the Job. </throws> /// <remarks> /// It should be extremely rare for this method to throw an exception - /// basically only the the case where there is no way at all to instantiate /// and prepare the Job for execution. When the exception is thrown, the /// Scheduler will move all triggers associated with the Job into the /// <see cref="F:Quartz.TriggerState.Error" /> state, which will require human /// intervention (e.g. an application restart after fixing whatever /// configuration problem led to the issue wih instantiating the Job. /// </remarks> public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { try { if (this.container.HasComponent(bundle.JobDetail.JobType)) { this.logger.DebugFormat("Resolving component for job '{0}'.", bundle.JobDetail.JobType); return (IJob)this.container.Resolve(bundle.JobDetail.JobType); } this.logger.WarnFormat("No component registered for job '{0}'. Probably there are dirty data into the db", bundle.JobDetail.JobType); return null; } catch (Exception ex) { this.logger.FatalFormat("Unable to resolve the job '{0}'", ex, bundle.JobDetail.JobType); throw; } }
public void SetUp() { var cb = new ContainerBuilder(); _state = new State(); cb.RegisterInstance(_state); cb.RegisterType<WrappedJob>().InstancePerLifetimeScope(); _jobDetail = new Mock<IJobDetail>(); _jobDetail.SetupAllProperties(); _executionContext = new Mock<IJobExecutionContext>(); _executionContext.Setup(c => c.JobDetail) .Returns(_jobDetail.Object); _trigger = new Mock<IOperableTrigger>(); _calendar = new Mock<ICalendar>(); _container = cb.Build(); _bundle = new TriggerFiredBundle(_jobDetail.Object, _trigger.Object, _calendar.Object, false, null, null, null, null); _wrapper = new AutofacJobFactory.JobWrapper(_bundle, _container.Resolve<ILifetimeScope>(), "nested-scope"); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(_serviceProvider.GetRequiredService <JobRunner>()); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(new ScheduleExecutor(_logger)); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return((IJob)_context.Resolve(bundle.JobDetail.JobType)); }
private IJob GetEconomicReleaseJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(new EconomicReleaseUpdateJob(_erb, GetEmailSender(), _updateJobSettings)); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(container.GetService(bundle.JobDetail.JobType) as IJob); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { var job = _container.Resolve(bundle.JobDetail.JobType); return(job as IJob); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(_container.Resolve <IJob>(bundle.JobDetail.JobType)); }
public InterruptableJobWrapper(TriggerFiredBundle bundle, IUnityContainer unityContainer) : base(bundle, unityContainer) { }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(Container.GetService(bundle.JobDetail.JobType) as IJob); //throw new NotImplementedException(); }
public InterruptableJobWrapper(TriggerFiredBundle bundle, ILifetimeScope lifetimeScope, string scopeName) : base(bundle, lifetimeScope, scopeName) { }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Object" /> class. /// </summary> public JobWrapper(TriggerFiredBundle bundle, ILifetimeScope lifetimeScope, string scopeName) { if (bundle == null) throw new ArgumentNullException("bundle"); if (lifetimeScope == null) throw new ArgumentNullException("lifetimeScope"); if (scopeName == null) throw new ArgumentNullException("scopeName"); _bundle = bundle; _lifetimeScope = lifetimeScope; _scopeName = scopeName; }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) => _schedulerJobResolver.Resolve <IQuartzSchedulerJob>(bundle.JobDetail.JobType);
/// <summary> /// The main processing loop of the <see cref="QuartzSchedulerThread" />. /// </summary> public override void Run() { bool lastAcquireFailed = false; while (!halted) { try { // check if we're supposed to pause... lock (sigLock) { while (paused && !halted) { try { // wait until togglePause(false) is called... Monitor.Wait(sigLock, 1000); } catch (ThreadInterruptedException) { } } if (halted) { break; } } int availThreadCount = qsRsrcs.ThreadPool.BlockForAvailableThreads(); if (availThreadCount > 0) // will always be true, due to semantics of blockForAvailableThreads... { IList <IOperableTrigger> triggers = null; DateTimeOffset now = SystemTime.UtcNow(); ClearSignaledSchedulingChange(); try { triggers = qsRsrcs.JobStore.AcquireNextTriggers( now + idleWaitTime, Math.Min(availThreadCount, qsRsrcs.MaxBatchSize), qsRsrcs.BatchTimeWindow); lastAcquireFailed = false; if (log.IsDebugEnabled) { log.Debug("Batch acquisition of {0} triggers", (triggers == null ? 0 : triggers.Count)); } } catch (JobPersistenceException jpe) { if (!lastAcquireFailed) { qs.NotifySchedulerListenersError( "An error occurred while scanning for the next trigger to fire.", jpe); } lastAcquireFailed = true; } catch (Exception e) { if (!lastAcquireFailed) { Log.Error("quartzSchedulerThreadLoop: RuntimeException " + e.Message, e); } lastAcquireFailed = true; } if (triggers != null && triggers.Count > 0) { now = SystemTime.UtcNow(); DateTimeOffset triggerTime = triggers[0].GetNextFireTimeUtc().Value; TimeSpan timeUntilTrigger = triggerTime - now; while (timeUntilTrigger > TimeSpan.FromMilliseconds(2)) { if (ReleaseIfScheduleChangedSignificantly(triggers, triggerTime)) { break; } lock (sigLock) { if (halted) { break; } if (!IsCandidateNewTimeEarlierWithinReason(triggerTime, false)) { try { // we could have blocked a long while // on 'synchronize', so we must recompute now = SystemTime.UtcNow(); timeUntilTrigger = triggerTime - now; if (timeUntilTrigger > TimeSpan.Zero) { Monitor.Wait(sigLock, timeUntilTrigger); } } catch (ThreadInterruptedException) { } } } if (ReleaseIfScheduleChangedSignificantly(triggers, triggerTime)) { break; } now = SystemTime.UtcNow(); timeUntilTrigger = triggerTime - now; } // this happens if releaseIfScheduleChangedSignificantly decided to release triggers if (triggers.Count == 0) { continue; } // set triggers to 'executing' IList <TriggerFiredResult> bndles = new List <TriggerFiredResult>(); bool goAhead = true; lock (sigLock) { goAhead = !halted; } if (goAhead) { try { IList <TriggerFiredResult> res = qsRsrcs.JobStore.TriggersFired(triggers); if (res != null) { bndles = res; } } catch (SchedulerException se) { qs.NotifySchedulerListenersError("An error occurred while firing triggers '" + triggers + "'", se); // QTZ-179 : a problem occurred interacting with the triggers from the db // we release them and loop again foreach (IOperableTrigger t in triggers) { ReleaseTriggerRetryLoop(t); } continue; } } for (int i = 0; i < bndles.Count; i++) { TriggerFiredResult result = bndles[i]; TriggerFiredBundle bndle = result.TriggerFiredBundle; Exception exception = result.Exception; IOperableTrigger trigger = triggers[i]; // TODO SQL exception? if (exception != null && (exception is DbException || exception.InnerException is DbException)) { Log.Error("DbException while firing trigger " + trigger, exception); // db connection must have failed... keep // retrying until it's up... ReleaseTriggerRetryLoop(trigger); continue; } // it's possible to get 'null' if the triggers was paused, // blocked, or other similar occurrences that prevent it being // fired at this time... or if the scheduler was shutdown (halted) if (bndle == null) { try { qsRsrcs.JobStore.ReleaseAcquiredTrigger(trigger); } catch (SchedulerException se) { qs.NotifySchedulerListenersError( "An error occurred while releasing triggers '" + trigger.Key + "'", se); // db connection must have failed... keep retrying // until it's up... ReleaseTriggerRetryLoop(trigger); } continue; } // TODO: improvements: // // 2- make sure we can get a job runshell before firing trigger, or // don't let that throw an exception (right now it never does, // but the signature says it can). // 3- acquire more triggers at a time (based on num threads available?) JobRunShell shell = null; try { shell = qsRsrcs.JobRunShellFactory.CreateJobRunShell(bndle); shell.Initialize(qs); } catch (SchedulerException) { try { qsRsrcs.JobStore.TriggeredJobComplete(trigger, bndle.JobDetail, SchedulerInstruction.SetAllJobTriggersError); } catch (SchedulerException se2) { qs.NotifySchedulerListenersError( "An error occurred while placing job's triggers in error state '" + trigger.Key + "'", se2); // db connection must have failed... keep retrying // until it's up... ErrorTriggerRetryLoop(bndle); } continue; } if (qsRsrcs.ThreadPool.RunInThread(shell) == false) { try { // this case should never happen, as it is indicative of the // scheduler being shutdown or a bug in the thread pool or // a thread pool being used concurrently - which the docs // say not to do... Log.Error("ThreadPool.runInThread() return false!"); qsRsrcs.JobStore.TriggeredJobComplete(trigger, bndle.JobDetail, SchedulerInstruction. SetAllJobTriggersError); } catch (SchedulerException se2) { qs.NotifySchedulerListenersError( string.Format(CultureInfo.InvariantCulture, "An error occurred while placing job's triggers in error state '{0}'", trigger.Key), se2); // db connection must have failed... keep retrying // until it's up... ReleaseTriggerRetryLoop(trigger); } } } continue; // while (!halted) } } else // if(availThreadCount > 0) { // should never happen, if threadPool.blockForAvailableThreads() follows contract continue; // while (!halted) } DateTimeOffset utcNow = SystemTime.UtcNow(); DateTimeOffset waitTime = utcNow.Add(GetRandomizedIdleWaitTime()); TimeSpan timeUntilContinue = waitTime - utcNow; lock (sigLock) { if (!halted) { try { Monitor.Wait(sigLock, timeUntilContinue); } catch (ThreadInterruptedException) { } } } } catch (Exception re) { if (Log != null) { Log.Error("Runtime error occurred in main trigger firing loop.", re); } } } // while (!halted) // drop references to scheduler stuff to aid garbage collection... qs = null; qsRsrcs = null; }
/// <summary> /// Create a JobRunShell instance with the given settings. /// </summary> /// <param name="scheduler">The <see cref="IScheduler" /> instance that should be made /// available within the <see cref="IJobExecutionContext" />.</param> /// <param name="bndle"></param> public JobRunShell(IScheduler scheduler, TriggerFiredBundle bndle) { this.scheduler = scheduler; this.firedTriggerBundle = bndle; log = LogManager.GetLogger(GetType()); }
public TriggerFiredBundle TriggerFired(Trigger trigger) { lock (_triggerLock) { TriggerWrapper tw = _triggersDictionary[trigger.Name] as TriggerWrapper; // was the trigger deleted since being acquired? if (tw == null || tw.Trigger == null) return null; // was the trigger completed since being acquired? if (tw.State == InternalTriggerState.Complete) return null; // was the trigger paused since being acquired? if (tw.State == InternalTriggerState.Paused) return null; // was the trigger blocked since being acquired? if (tw.State == InternalTriggerState.Blocked) return null; // was the trigger paused and blocked since being acquired? if (tw.State == InternalTriggerState.PausedAndBlocked) return null; NullableDateTime prevFireTime = trigger.GetPreviousFireTimeUtc(); // in case trigger was replaced between acquiring and firering _timeTriggers.Remove(tw); trigger.Triggered(); //tw.state = TriggerWrapper.StateExecuting; tw.State = InternalTriggerState.Waiting; IScheduledJob job = RetrieveJob(trigger.JobName); TriggerFiredBundle bndle = new TriggerFiredBundle(job, trigger, false, DateTime.UtcNow, trigger.GetPreviousFireTimeUtc(), prevFireTime, trigger.GetNextFireTimeUtc()); NullableDateTime d = tw.Trigger.GetNextFireTimeUtc(); if (d.HasValue) { lock (_triggerLock) { _timeTriggers.Add(tw); } } return bndle; } }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return((IJob)_resolutionRoot.Get(bundle.JobDetail.JobType)); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { var job = _serviceProvider.GetService(bundle.JobDetail.JobType) as IJob; return(job); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { var jobType = bundle.JobDetail.JobType; return(ObjectUtils.InstantiateType <IJob>(jobType)); }
/// <summary> /// The main processing loop of the <see cref="QuartzSchedulerThread" />. /// </summary> public async Task Run() { bool lastAcquireFailed = false; while (!halted) { cancellationTokenSource.Token.ThrowIfCancellationRequested(); try { // check if we're supposed to pause... lock (sigLock) { while (paused && !halted) { try { // wait until togglePause(false) is called... Monitor.Wait(sigLock, 1000); } catch (ThreadInterruptedException) { } } if (halted) { break; } } cancellationTokenSource.Token.ThrowIfCancellationRequested(); int availThreadCount = qsRsrcs.ThreadPool.BlockForAvailableThreads(); if (availThreadCount > 0) { List <IOperableTrigger> triggers; DateTimeOffset now = SystemTime.UtcNow(); ClearSignaledSchedulingChange(); try { var noLaterThan = now + idleWaitTime; var maxCount = Math.Min(availThreadCount, qsRsrcs.MaxBatchSize); triggers = new List <IOperableTrigger>(await qsRsrcs.JobStore.AcquireNextTriggers(noLaterThan, maxCount, qsRsrcs.BatchTimeWindow, CancellationToken.None).ConfigureAwait(false)); lastAcquireFailed = false; if (Log.IsDebugEnabled()) { Log.DebugFormat("Batch acquisition of {0} triggers", triggers?.Count ?? 0); } } catch (JobPersistenceException jpe) { if (!lastAcquireFailed) { var msg = "An error occurred while scanning for the next trigger to fire."; await qs.NotifySchedulerListenersError(msg, jpe, CancellationToken.None).ConfigureAwait(false); } lastAcquireFailed = true; await HandleDbRetry(CancellationToken.None); continue; } catch (Exception e) { if (!lastAcquireFailed) { Log.ErrorException("quartzSchedulerThreadLoop: RuntimeException " + e.Message, e); } lastAcquireFailed = true; await HandleDbRetry(CancellationToken.None); continue; } if (triggers != null && triggers.Count > 0) { now = SystemTime.UtcNow(); DateTimeOffset triggerTime = triggers[0].GetNextFireTimeUtc().Value; TimeSpan timeUntilTrigger = triggerTime - now; while (timeUntilTrigger > TimeSpan.Zero) { if (await ReleaseIfScheduleChangedSignificantly(triggers, triggerTime).ConfigureAwait(false)) { break; } lock (sigLock) { if (halted) { break; } if (!IsCandidateNewTimeEarlierWithinReason(triggerTime, false)) { try { // we could have blocked a long while // on 'synchronize', so we must recompute now = SystemTime.UtcNow(); timeUntilTrigger = triggerTime - now; if (timeUntilTrigger > TimeSpan.Zero) { Monitor.Wait(sigLock, timeUntilTrigger); } } catch (ThreadInterruptedException) { } } } if (await ReleaseIfScheduleChangedSignificantly(triggers, triggerTime).ConfigureAwait(false)) { break; } now = SystemTime.UtcNow(); timeUntilTrigger = triggerTime - now; } // this happens if releaseIfScheduleChangedSignificantly decided to release triggers if (triggers.Count == 0) { continue; } // set triggers to 'executing' List <TriggerFiredResult> bndles = new List <TriggerFiredResult>(); bool goAhead; lock (sigLock) { goAhead = !halted; } if (goAhead) { try { var res = await qsRsrcs.JobStore.TriggersFired(triggers, CancellationToken.None).ConfigureAwait(false); if (res != null) { bndles = res.ToList(); } } catch (SchedulerException se) { var msg = "An error occurred while firing triggers '" + triggers + "'"; await qs.NotifySchedulerListenersError(msg, se, CancellationToken.None).ConfigureAwait(false); // QTZ-179 : a problem occurred interacting with the triggers from the db // we release them and loop again foreach (IOperableTrigger t in triggers) { await qsRsrcs.JobStore.ReleaseAcquiredTrigger(t, CancellationToken.None).ConfigureAwait(false); } continue; } } for (int i = 0; i < bndles.Count; i++) { TriggerFiredResult result = bndles[i]; TriggerFiredBundle bndle = result.TriggerFiredBundle; Exception exception = result.Exception; IOperableTrigger trigger = triggers[i]; // TODO SQL exception? if (exception != null && (exception is DbException || exception.InnerException is DbException)) { Log.ErrorException("DbException while firing trigger " + trigger, exception); await qsRsrcs.JobStore.ReleaseAcquiredTrigger(trigger, CancellationToken.None).ConfigureAwait(false); continue; } // it's possible to get 'null' if the triggers was paused, // blocked, or other similar occurrences that prevent it being // fired at this time... or if the scheduler was shutdown (halted) if (bndle == null) { await qsRsrcs.JobStore.ReleaseAcquiredTrigger(trigger, CancellationToken.None).ConfigureAwait(false); continue; } // TODO: improvements: // // 2- make sure we can get a job runshell before firing trigger, or // don't let that throw an exception (right now it never does, // but the signature says it can). // 3- acquire more triggers at a time (based on num threads available?) JobRunShell shell; try { shell = qsRsrcs.JobRunShellFactory.CreateJobRunShell(bndle); await shell.Initialize(qs, CancellationToken.None).ConfigureAwait(false); } catch (SchedulerException) { await qsRsrcs.JobStore.TriggeredJobComplete(trigger, bndle.JobDetail, SchedulerInstruction.SetAllJobTriggersError, CancellationToken.None).ConfigureAwait(false); continue; } var threadPoolRunResult = qsRsrcs.ThreadPool.RunInThread(() => shell.Run(CancellationToken.None)); if (threadPoolRunResult == false) { // this case should never happen, as it is indicative of the // scheduler being shutdown or a bug in the thread pool or // a thread pool being used concurrently - which the docs // say not to do... Log.Error("ThreadPool.RunInThread() returned false!"); await qsRsrcs.JobStore.TriggeredJobComplete(trigger, bndle.JobDetail, SchedulerInstruction.SetAllJobTriggersError, CancellationToken.None).ConfigureAwait(false); } } continue; // while (!halted) } } else // if(availThreadCount > 0) { continue; // while (!halted) } DateTimeOffset utcNow = SystemTime.UtcNow(); DateTimeOffset waitTime = utcNow.Add(GetRandomizedIdleWaitTime()); TimeSpan timeUntilContinue = waitTime - utcNow; lock (sigLock) { if (!halted) { try { // QTZ-336 A job might have been completed in the mean time and we might have // missed the scheduled changed signal by not waiting for the notify() yet // Check that before waiting for too long in case this very job needs to be // scheduled very soon if (!IsScheduleChanged()) { Monitor.Wait(sigLock, timeUntilContinue); } } catch (ThreadInterruptedException) { } } } } catch (Exception re) { Log.ErrorException("Runtime error occurred in main trigger firing loop.", re); } } // while (!halted) }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(new JobWrapper(_provider, bundle.JobDetail.JobType)); }
private IJob GetDataUpdateJob(TriggerFiredBundle bundle, IScheduler scheduler) { //only provide the email sender if data exists to properly initialize it with return(new DataUpdateJob(_hdb, GetEmailSender(), _updateJobSettings, _localStorage, new InstrumentRepository(new MyDBContext()))); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return((IJob)Container.GetInstance(bundle.JobDetail.JobType)); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(Factory.Create(bundle.JobDetail.JobType) as IJob); }
/// <summary> /// Create an instance of the specified job class. /// <p> /// Can be overridden to post-process the job instance. /// </p> /// </summary> /// <param name="bundle"> /// The TriggerFiredBundle from which the JobDetail /// and other info relating to the trigger firing can be obtained. /// </param> /// <returns>The job instance.</returns> protected virtual object CreateJobInstance(TriggerFiredBundle bundle) { return(ObjectUtils.InstantiateType(bundle.JobDetail.JobType)); }
protected virtual IJob InstantiateJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(base.NewJob(bundle, scheduler)); }
/// <summary> /// 获取一个Job /// </summary> /// <param name="bundle">触发器发射束?</param> /// <param name="scheduler">调度器</param> /// <returns></returns> public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(_iocResolver.Resolve(bundle.JobDetail.JobType).As <IJob>()); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(serviceProvider.GetService(typeof(IJob)) as IJob); }
/// <summary> /// Create a JobRunShell instance with the given settings. /// </summary> /// <param name="scheduler">The <see cref="IScheduler" /> instance that should be made /// available within the <see cref="IJobExecutionContext" />.</param> /// <param name="bundle"></param> public JobRunShell(IScheduler scheduler, TriggerFiredBundle bundle) { this.scheduler = scheduler; firedTriggerBundle = bundle; log = NLog.LogManager.GetCurrentClassLogger(); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { var jobType = bundle.JobDetail.JobType; return(Activator.CreateInstance(jobType, _service) as IJob); }
/// <inheritdoc /> public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { Logger.Debug("Get new observer job"); return(new CallObserversWithNewDataJob(this.observers)); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(_serviceProvider.GetRequiredService(bundle.JobDetail.JobType) as IJob); }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(serviceProvider.GetService <HttpJob>()); }
/// <summary> /// Called by the scheduler at the time of the trigger firing, in order to /// produce a <see cref="T:Quartz.IJob" /> instance on which to call Execute. /// </summary> /// <remarks> /// It should be extremely rare for this method to throw an exception - /// basically only the the case where there is no way at all to instantiate /// and prepare the Job for execution. When the exception is thrown, the /// Scheduler will move all triggers associated with the Job into the /// <see cref="F:Quartz.TriggerState.Error" /> state, which will require human /// intervention (e.g. an application restart after fixing whatever /// configuration problem led to the issue wih instantiating the Job. /// </remarks> /// <param name="bundle"> /// The TriggerFiredBundle from which the <see cref="T:Quartz.IJobDetail" /> /// and other info relating to the trigger firing can be obtained. /// </param> /// <param name="scheduler">a handle to the scheduler that is about to execute the job</param> /// <throws>SchedulerException if there is a problem instantiating the Job. </throws> /// <returns> /// the newly instantiated Job /// </returns> public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { if (bundle == null) throw new ArgumentNullException("bundle"); if (scheduler == null) throw new ArgumentNullException("scheduler"); var jobType = bundle.JobDetail.JobType; var nestedScope = _lifetimeScope.BeginLifetimeScope(_scopeName); IJob newJob = null; try { newJob = (IJob) nestedScope.Resolve(jobType); var jobTrackingInfo = new JobTrackingInfo(nestedScope); RunningJobs[newJob] = jobTrackingInfo; if (s_log.IsDebugEnabled) { s_log.DebugFormat(CultureInfo.InvariantCulture, "Scope 0x{0:x} associated with Job 0x{1:x}", jobTrackingInfo.Scope.GetHashCode(), newJob.GetHashCode()); } nestedScope = null; } catch (Exception ex) { if (nestedScope != null) { DisposeScope(newJob, nestedScope); } throw new SchedulerConfigException(string.Format(CultureInfo.InvariantCulture, "Failed to instantiate Job '{0}' of type '{1}'", bundle.JobDetail.Key, bundle.JobDetail.JobType), ex); } return newJob; }
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { return(new TaskJob(_service)); }