/// <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)); } } } }
private bool CanProcessJob() { return(PendingJobQueue.Any() && RunningJobs.Count < MaxScrapers); }
/// <summary> /// Queue up a job for processing. /// </summary> public void QueueJob(Job job) { job.Status = JobStatus.Pending; JobRepository.Save(job); PendingJobQueue.Enqueue(job); }