private readonly TimeSpan directorPollingInterval = new TimeSpan(0, 0, 5); // 5 sec. #region IManagerCoreServices Members private WorkerRunner FindWorkerRunner(string workerId) { WorkerRunner workerRunner; bool found = AllWorkerRunners.TryGetValue(workerId, out workerRunner); if (found) { return(workerRunner); } return(null); }
private void RemoveWorkerRunnersForNotPresentWorkers() { foreach (var workerRunner in AllWorkerRunners.Values.Where(wr => !wr.IsPresent).ToList()) { AllWorkerRunners.Remove(workerRunner.WorkAssignment.WorkerId); Tracer.Info("Removed WorkerRunner for the worker {0} as it is not present anymore.", workerRunner.WorkAssignment.WorkerId); if (workerRunner.QuitGracefully) { workerRunner.CommittableTransaction.Commit(); //Tracer.Debug("Employment transaction commited for worker {0}.", workerRunner.WorkAssignment.WorkerId); } else { workerRunner.CommittableTransaction.Rollback(); Tracer.Warning("Employment transaction rolled back for worker {0}.", workerRunner.WorkAssignment.WorkerId); } workerRunner.CommittableTransaction.Dispose(); } }
// Returns false when runningJob is ready to be removed from the list of running jobs and disposed private bool StopWorkersForJob(RunningJob runningJob) { Tracer.Info("Stopping workers for a job. PipelineId = {0}", runningJob.PipelineId); runningJob.State = RunningJob.States.ReadyForDispose; // Just an unconfirmed attempt so far if (runningJob.Sections != null) { foreach (JobSection jobSection in runningJob.Sections) { foreach (string workerID in jobSection.WorkerIDs) { WorkerRunner workerRunner = FindWorkerRunner(workerID); if (null == workerRunner) { continue; } if (workerRunner.IsPresent) { //Tracer.Trace("StopWorkersForJob: Worker {0} is still active. Commanding it to quit.", workerRunner.WorkAssignment.WorkerId); workerRunner.Command = Command.Cancel; runningJob.State = RunningJob.States.WaitingForWorkersToQuit; } else { Tracer.Info("StopWorkersForJob: Worker {0} quit. Removing worker runner object.", workerRunner.WorkAssignment.WorkerId); AllWorkerRunners.Remove(workerRunner.WorkAssignment.WorkerId); workerRunner.CommittableTransaction.Commit(); workerRunner.CommittableTransaction.Dispose(); } } } } //Tracer.Trace("runningJob.PipelineId = {0}, runningJob.State = {1}", runningJob.PipelineId, runningJob.State.ToString()); if (runningJob.State == RunningJob.States.ReadyForDispose) { // TODO: Properly dispose JobSections here Tracer.Info("Disposed its resources pertained to job with PipelineId = {0}", runningJob.PipelineId); return(false); } return(true); }
internal void EmployWorker(WorkerCard workerCard, WorkAssignment workAssignment, CommittableTransaction committableTransaction) { WorkerRunner workerRunner = null; switch (workAssignment.WorkRequest.WorkerIsolationLevel) { case WorkerIsolationLevel.SeparateAppDomain: workerRunner = new WorkerRunnerAppDomain(workerCard, workAssignment, committableTransaction); break; case WorkerIsolationLevel.SeparateProcess: workerRunner = new WorkerRunnerProcess(workerCard, workAssignment, committableTransaction); // Debug //workerRunner = new WorkerRunnerThread(workerCard, WorkAssignment, committableTransaction); break; case WorkerIsolationLevel.SeparateThread: case WorkerIsolationLevel.Default: default: workerRunner = new WorkerRunnerThread(workerCard, workAssignment, committableTransaction); break; } try { AllWorkerRunners.Add(workAssignment.WorkerId, workerRunner); } catch (Exception ex) { Tracer.Error("AllWorkerRunners.Add({0}) caused exception: {1}", workAssignment.WorkerId, ex); foreach (string workerId in AllWorkerRunners.Keys) { Tracer.Error("AllWorkerRunners contains worker {0}", workerId); } throw; } workerRunner.Run(); }