/// <summary> /// This method executes all the containing jobs. /// </summary> /// <param name="Timeout">The timeout period in which the job should execute in its entirity.</param> public void Execute(int Timeout, bool traceOutput) { mJobShouldTrace = traceOutput; if (autoExecute) { mStatus = CompletionJobStatus.Processing; CheckCompletionJobComplete(); return; } if (mStatus != CompletionJobStatus.Unset) throw new JobException("The CompletionJob has already started executing. Call Reset()."); mStatus = CompletionJobStatus.Processing; foreach(Guid jobID in WorkTable.JobIDs) { SubmitJob(jobID); } if (Timeout>-1) SetTimer(Timeout); }
/// <summary> /// This method can be called to signal that a completion job is complete. /// </summary> public void SubmitComplete() { if (!autoExecute) throw new JobException("SubmitComplete can only be called to completion jobs that have autocomplete set to true."); lock (this) { mStatus = CompletionJobStatus.Processing; CheckCompletionJobComplete(); } }
/// <summary> /// This method is called when the job times out. /// </summary> /// <param name="state"></param> protected override void OnTimeOut(object state) { base.OnTimeOut(state); mStatus = CompletionJobStatus.TimeOut; CompletionJobComplete(this.ParentJob, CompletionJobStatus.TimeOut, State); }
/// <summary> /// This private method initializes the completion job. /// </summary> /// <param name="job">The parent job.</param> /// <param name="callback">The completion callback.</param> /// <param name="state">The object state.</param> /// <param name="AutoExecute">This method identifies whether the jobs will execute automatically and only signal after the complete method has been set.</param> /// <param name="throttleThreshold">The throttle threshold is the amount of queued jobs that /// will trigger the throttle flag to be set.</param> /// <param name="trace">The trace flag determines whether the completion job should submit trace /// data during the job processing.</param> protected void Initialize(SecurityManagerJob job, CompletionJobCallBack callback, object state, bool AutoExecute, int throttleThreshold, bool trace) { mParentJob = job; CompletionJobComplete = callback; mState = state; autoExecute=AutoExecute; if (autoExecute) mStatus = CompletionJobStatus.Submitting; mJobShouldTrace = trace; if (mDependencyList != null) mDependencyList.Clear(); errorList.Clear(); errorCount = 0; this.throttleThreshold = throttleThreshold; if (throttleThreshold > 0) { if (mThrottlingQueue == null) mThrottlingQueue = new Queue<JobHolder>(); else mThrottlingQueue.Clear(); } ThrottleSet(); executingJobs = 0; }
/// <summary> /// This private method reset the Completion job. /// </summary> public override void Reset() { base.Reset(); mState = null; mStatus = CompletionJobStatus.Unset; CompletionJobComplete = null; //internalCallback = null; ThrottleSet(); autoExecute = false; mJobShouldTrace = false; delCompletionJobReturn = null; }
/// <summary> /// This method completes the job if it is not already completed. /// </summary> protected virtual bool CheckCompletionJobComplete() { lock(this) { if (jobRequests > 0) return false; if (mThrottlingQueue != null && mThrottlingQueue.Count > 0) return false; //If there are more jobs to process then exit. if (mStatus == CompletionJobStatus.Submitting || mStatus == CompletionJobStatus.Complete) return false; //This completion job has completed. mStatus = CompletionJobStatus.Complete; } try { if (CompletionJobComplete != null) CompletionJobComplete(this.ParentJob, CompletionJobStatus.Complete, State); delCompletionJobReturn(this); } catch (Exception ex) { throw ex; } finally { ThrottleSet(); } return true; }