Beispiel #1
0
        /// <summary>
        /// Remove jobs when they succeed/fail
        /// </summary>
        private void ProcessRunningJob(Job job)
        {
            if (!RunningJobs.TryGetValue(job, out var scrapeResult))
            {
                return;
            }

            lock (lockObject)
            {
                if (scrapeResult.IsCompleted)
                {
                    var result = RunningJobs[job].Result;

                    if (result.Error != null)
                    {
                        job.Status = JobStatus.Failed;
                        job.Result = new Dictionary <string, IEnumerable <string> >
                        {
                            { "Error", new List <string> {
                                  scrapeResult.Exception.GetFullExceptionMessage()
                              } }
                        };
                    }
                    else
                    {
                        job.Status = JobStatus.Completed;
                        job.Result = result.Scrape;
                    }

                    JobRepository.Save(job);
                    RunningJobs.TryRemove(job, out var removedJob);
                }
                else if (scrapeResult.IsFaulted)
                {
                    job.Status = JobStatus.Failed;
                    job.Result = new Dictionary <string, IEnumerable <string> >
                    {
                        { "Error", new List <string> {
                              scrapeResult.Exception.GetFullExceptionMessage()
                          } }
                    };

                    JobRepository.Save(job);
                    RunningJobs.TryRemove(job, out var removedJob);
                }
            }
        }