private void PollCancellingJobs() { List <Job> temp = new List <Job>(); using (var context = ContextManager.Instance.CreateContext(ConnectionMode.AutoOpen, TransactionMode.AutoCommit)) { var jf = new JobInstanceFactory(context); foreach (var queue in Cluster.Queues.Values) { foreach (var ji in jf.FindJobInstances(Guid.Empty, queue.Guid, null, JobExecutionState.CancelRequested)) { lock (queue) { if (queue.Jobs.ContainsKey(ji.Guid)) { temp.Add(queue.Jobs[ji.Guid]); } } } } } // This is to be done outside the registry context foreach (var job in temp) { CancelOrTimeOutJob(job, false); } }
protected void PurgeTestJobs() { using (var context = ContextManager.Instance.CreateContext(ConnectionMode.AutoOpen, TransactionMode.AutoCommit)) { var ef = new EntityFactory(context); var jd = ef.LoadEntity <JobDefinition>(Registry.AppSettings.ClusterName, Registry.Constants.SharedDomainName, Registry.Constants.SharedFederationName, typeof(Jhu.Graywulf.Jobs.Test.TestJob).Name); var jf = new JobInstanceFactory(context); foreach (var job in jf.FindJobInstances(Guid.Empty, Guid.Empty, new HashSet <Guid>() { jd.Guid }, JobExecutionState.Scheduled)) { job.Cancel(); } } }
/// <summary> /// Process jobs that are found in an intermediate stage, possibly /// due to an unexpected shutdown of the scheduler. /// </summary> private void ProcessInterruptedJobs() { using (Context context = ContextManager.Instance.CreateContext(ConnectionMode.AutoOpen, TransactionMode.AutoCommit)) { int q; Event e; var jf = new JobInstanceFactory(context); q = 1; foreach (var qi in Cluster.Queues.Keys) { // Process previously interrupted jobs (that are marked as running) // Process jobs that are marked as executing - these remained in this state // because of a failure in the scheduler foreach (var j in jf.FindJobInstances(Guid.Empty, qi, null, JobExecutionState.Executing | JobExecutionState.Persisting | JobExecutionState.Cancelling)) { // Locking must be handled context.ContextGuid = j.WorkflowInstanceId; j.ReleaseLock(true); j.JobExecutionStatus = JobExecutionState.Failed; j.ExceptionMessage = Jhu.Graywulf.Registry.ExceptionMessages.SchedulerUnexpectedShutdown; j.Save(); j.RescheduleIfRecurring(); q++; } } if (q > 0) { e = new Event("Jhu.Graywulf.Scheduler.QueueManager.ProcessInterruptedJobs[Executing]", Guid.Empty); e.Message = String.Format("Marked {0} jobs as failed.", q); LogEvent(e); } q = 0; foreach (var qi in Cluster.Queues.Keys) { // Jobs marked as waiting probably can be restarted without a side effect foreach (var j in jf.FindJobInstances(Guid.Empty, qi, null, JobExecutionState.Starting)) { // Locking must be handled context.ContextGuid = j.WorkflowInstanceId; j.ReleaseLock(true); j.JobExecutionStatus = JobExecutionState.Scheduled; j.Save(); q++; } } if (q > 0) { e = new Event("Jhu.Graywulf.Scheduler.QueueManager.ProcessInterruptedJobs[Starting]", Guid.Empty); e.Message = String.Format("Marked {0} jobs as scheduled.", q); LogEvent(e); } } }