/// <summary> /// Perfoms build state on job start event. /// </summary> /// <param name="job"> /// Job to start. /// </param> public void Build(Job job) { Contract.Requires(job != null); Contract.Requires(job.State == JobState.Ready); throw new NotImplementedException(); }
private static string BuildObjectGraph(Job job) { var sb = new StringBuilder(); sb.AppendFormat("Task graph for job {0}:", job).AppendLine(); foreach (var task in job.Tasks) { sb.AppendFormat("{0}:", task).AppendLine().AppendLine("Dependencies:"); foreach (var input in task.Inputs) { sb.AppendFormat(" - {0}", input).AppendLine(); } sb.AppendFormat("{0}:", task).AppendLine().AppendLine("Dependents:"); foreach (var output in task.Outputs) { sb.AppendFormat(" - {0}", output).AppendLine(); } sb.AppendLine(); } return sb.ToString(); }
/// <summary> /// Perfoms build state on job start event. /// </summary> /// <param name="job"> /// Job to start. /// </param> public void Build(Job job) { if (!job.Tasks.All(task => RecoursiveCheckGraph(task, ImmutableList<Guid>.Empty))) throw new InvalidJobException( "Job graph contains cycles. ", job.Id); }
/// <summary> /// Perfoms build state on job start event. /// </summary> /// <param name="job"> /// Job to start. /// </param> public void Build(Job job) { Logger.Write( LogCategories.Information("Clearing outputs...", LogCategories.TaskServices, LogCategories.JobGraphCompletionStrategy)); foreach (var task in job.Tasks) { task.Outputs.Clear(); } Logger.Write( LogCategories.Information("Building outputs...", LogCategories.TaskServices, LogCategories.JobGraphCompletionStrategy)); foreach (var task in job.Tasks) { foreach (var input in task.Inputs) { input.Outputs.Add(task); } } Logger.Write( LogCategories.Information(BuildObjectGraph(job), LogCategories.TaskServices, LogCategories.JobGraphCompletionStrategy)); }
/// <summary> /// Cancels execution of specified job. /// </summary> /// <param name="job"> /// An instance of <see cref="Job"/>. /// </param> public void CancelJob(Job job) { Contract.Requires(job != null); Contract.Requires(job.State == JobState.Processing); Contract.Ensures(job.State == JobState.Cancelled); throw new NotImplementedException(); }
/// <summary> /// Removes job from scheduler. /// </summary> /// <param name="job"> /// An instance of <see cref="Job"/>. /// </param> public void DeleteJob(Job job) { Contract.Requires(job != null); Contract.Requires(job.State == JobState.Ready || job.State == JobState.Cancelled || job.State == JobState.Failed || job.State == JobState.Completed || job.State == JobState.Deleted); Contract.Ensures(job.State == JobState.Deleted); throw new NotImplementedException(); }
/// <summary> /// Builds the job on job start event. /// </summary> /// <param name="job"> /// Job to build. /// </param> public void Build(Job job) { foreach (var strategy in Strategies) { Logger.Write( LogCategories.Information(string.Format("Perfoming {0} on {1}", strategy.GetType().Name, job), LogCategories.TaskServices, LogCategories.TaskProviderService)); strategy.Build(job); } }
/// <summary> /// Cancels execution of specified job. /// </summary> /// <param name="job"> /// An instance of <see cref="Job"/>. /// </param> public void CancelJob(Job job) { UnsubscribeFromJob(job); foreach (var task in job.Tasks) { taskQueue.CancelTask(task); } job.State = JobState.Cancelled; }
/// <summary> /// Removes job from scheduler. /// </summary> /// <param name="job"> /// An instance of <see cref="Job"/>. /// </param> public void DeleteJob(Job job) { foreach (var task in job.Tasks) { taskQueue.DeleteTask(task); } jobs.Remove(job); job.State = JobState.Deleted; }
private void SubscribeToJob(Job job) { job.OnJobCompleted += Job_OnJobCompleted; job.OnJobFailed += Job_OnJobFailed; }
private void UnsubscribeFromJob(Job job) { try { job.OnJobCompleted -= Job_OnJobCompleted; } catch (Exception e) { Logger.Write( LogCategories.Error(string.Format("UnsubscribeFromJob({0}):\n{1}", job, e), LogCategories.TaskServices, LogCategories.JobScheduler)); } }
/// <summary> /// Starts executin of specified job. /// </summary> /// <param name="job"> /// An instance of <see cref="Job"/>. /// </param> public void StartJob(Job job) { Logger.Write( LogCategories.Information(string.Format("Job {0} started.", job), LogCategories.TaskServices, LogCategories.JobScheduler)); // Subscribe to current job's events. SubscribeToJob(job); // Build the current job. jobBuildingPipeline.Build(job); foreach (var task in job.Tasks) { taskQueue.StartTask(task); } job.State = JobState.Processing; }
private void InvokeOnJobFailed(Job job) { var handler = OnJobFailed; if (handler != null) handler(this, new JobEventArgs(job)); }
/// <summary> /// Reinitializes cancelled job. /// </summary> /// <param name="job"> /// An instance of <see cref="Job"/>. /// </param> public void RestartJob(Job job) { job.InitJobState(); foreach (var task in job.Tasks) { taskQueue.RestartTask(task); } job.State = JobState.Ready; }
/// <summary> /// Registers newly created job in manager and sets job's UID. /// </summary> /// <param name="job"> /// An instance of <see cref="Job"/>. /// </param> public void RegisterJob(Job job) { Contract.Requires(job != null); Contract.Requires(job.State == JobState.Creating); Contract.Ensures(job.State == JobState.Ready); throw new NotImplementedException(); }
/// <summary> /// Reinitializes cancelled job. /// </summary> /// <param name="job"> /// An instance of <see cref="Job"/>. /// </param> public void RestartJob(Job job) { Contract.Requires(job != null); Contract.Requires(job.State == JobState.Cancelled); Contract.Ensures(job.State == JobState.Ready); throw new NotImplementedException(); }
/// <summary> /// Creates new instance of <see cref="Job"/>. /// </summary> /// <param name="name"> /// Job's name. /// </param> /// <returns> /// New instance of <see cref="Job"/>. /// </returns> public Job CreateJob(string name) { var job = new Job(name) { Id = Guid.NewGuid(), State = JobState.Creating }; jobs.Add(job); return job; }
/// <summary> /// Perfoms build state on job start event. /// </summary> /// <param name="job"> /// Job to start. /// </param> public void Build(Job job) { Logger.Write(LogCategories.Information(string.Format("Initializing job {{{0}}}", job), LogCategories.TaskServices)); job.InitJobState(); }
/// <summary> /// Registers newly created job in manager and sets job's UID. /// </summary> /// <param name="job"> /// An instance of <see cref="Job"/>. /// </param> public void RegisterJob(Job job) { Logger.Write( LogCategories.Information(string.Format("Job {0} is created.", job), LogCategories.TaskServices, LogCategories.JobScheduler)); foreach (var task in job.Tasks) { taskQueue.RegisterTask(task); } job.State = JobState.Ready; }
/// <summary> /// Initalizes new instance of <see cref="JobEventArgs"/> class. /// </summary> /// <param name="job"> /// An instance of <see cref="Job"/> that provides data for current event. /// </param> public JobEventArgs(Job job) { Job = job; }