/// <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));
        }
Exemplo n.º 5
0
        /// <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();
        }
Exemplo n.º 6
0
        /// <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();
        }
Exemplo n.º 7
0
        /// <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);
            }
        }
Exemplo n.º 8
0
        /// <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;
        }
Exemplo n.º 9
0
        /// <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;
        }
Exemplo n.º 10
0
 private void SubscribeToJob(Job job)
 {
     job.OnJobCompleted += Job_OnJobCompleted;
     job.OnJobFailed += Job_OnJobFailed;
 }
Exemplo n.º 11
0
 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));
     }
 }
Exemplo n.º 12
0
        /// <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;
        }
Exemplo n.º 13
0
 private void InvokeOnJobFailed(Job job)
 {
     var handler = OnJobFailed;
     if (handler != null)
         handler(this, new JobEventArgs(job));
 }
Exemplo n.º 14
0
        /// <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;
        }
Exemplo n.º 15
0
        /// <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();
        }
Exemplo n.º 16
0
        /// <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();
        }
Exemplo n.º 17
0
        /// <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();
 }
Exemplo n.º 19
0
        /// <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;
        }
Exemplo n.º 20
0
 /// <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;
 }