Ejemplo n.º 1
0
        public override void Execute(
            Japi.Job job,
            Action<string> updateStatus,
            IRepository repositoryService,
            IJobManager jobManager)
        {
            var timer = Stopwatch.StartNew();
            jobManager.OpenJob(job.Id);
            jobManager.StartJob();

            while(true)
            {
                var state = jobManager.QueryJobState(job.Id);

                if(state == JobState.Completed)
                {
                    timer.Stop();
                    updateStatus(string.Format("Job completed in {0} ms", timer.ElapsedMilliseconds));
                    return;
                }

                if(state == JobState.Failed)
                {
                    timer.Stop();
                    using (ConsoleMessage.Error())
                    {
                        updateStatus("Job failed. Loading error report...");
                        var summary = jobManager.GetErrorReport(job.Id);
                        updateStatus(string.Format("Error report for job {{{0}, \"{1}\"}}", summary.JobId,
                                                   summary.JobName));
                        foreach (var report in summary.Errors)
                        {
                            updateStatus(string.Format("Task {{{0}, \"{1}\"}}: {2}",
                                                       report.Task.Id, report.Task.Name, report.Error));
                        }
                    }
                    return;
                }

                Thread.Sleep(100);
            }
        }
Ejemplo n.º 2
0
        public override void Execute(
            JobDefinition job,
            Action<int, int> notifyProgress,
            Action<string> updateStatus,
            IRepository repositoryService,
            IJobManager jobManager)
        {
            updateStatus("Executing job...");
            JobExecutingView dialog = null;

            Owner.Synch(() => dialog = new JobExecutingView(string.Format("Executing job {0}...", job)));

            jobManager.OpenJob(job.Id);
            jobManager.StartJob();

            var isWorking = true;

            dialog.OnCancelled += (s, e) =>
            {
                lock (this)
                {
                    if (!isWorking)
                        return;
                    isWorking = false;
                }

                jobManager.CancelJob();
            };
            Owner.Synch(() => dialog.Show());

            var state = default(JobState);
            while (isWorking)
            {
                state = jobManager.QueryJobState(job.Id);
                if (state == JobState.Completed ||
                   state == JobState.Failed)
                {
                    lock (this)
                    {
                        lock (this)
                            isWorking = false;
                        break;
                    }
                }

                Thread.Sleep(100);
            }
            Owner.Synch(() => dialog.Close());
            if (state == JobState.Completed)
            {
                return;
                // MessageBox.Show(string.Format("Job {0} completed!", job));
            }
            if (state == JobState.Failed)
            {
                var errorReport = jobManager.GetErrorReport(job.Id);
                Owner.Synch(() => ErrorReportView.ShowReport(errorReport));
                throw new StageFailedException("Job failed!");
                //MessageBox.Show(string.Format("Job {0} failed!", job));
            }
        }