Esempio n. 1
0
        /// <summary>
        /// Start any pending jobs as soon as we have capacity.
        /// </summary>
        private void ProcessWaitingJobs()
        {
            Job pendingJob = null;

            if (CanProcessJob())
            {
                lock (lockObject)
                {
                    if (CanProcessJob())
                    {
                        PendingJobQueue.TryDequeue(out pendingJob);
                        pendingJob.Status = JobStatus.Running;

                        JobRepository.Save(pendingJob);
                        RunningJobs.TryAdd(pendingJob, Scraper.ScrapeAsync(pendingJob.Url, pendingJob.Selectors));
                    }
                }
            }
        }
Esempio n. 2
0
 private bool CanProcessJob()
 {
     return(PendingJobQueue.Any() && RunningJobs.Count < MaxScrapers);
 }
Esempio n. 3
0
 /// <summary>
 /// Queue up a job for processing.
 /// </summary>
 public void QueueJob(Job job)
 {
     job.Status = JobStatus.Pending;
     JobRepository.Save(job);
     PendingJobQueue.Enqueue(job);
 }