示例#1
0
        static private void Run(string[] args)         //Main(string[] args)
        {
            using (var db = new CoreContext())
            {
                db.Database.Initialize(false);
            }

            bool isTestScraping = args.Any(a => a.Equals("-testScraping", StringComparison.InvariantCultureIgnoreCase));
            // Create scrapingWorker threads
            var scrapingWorker = new Worker(
                isTestScraping ? JobProducer.CreateTestScrapingProducer() : JobProducer.CreateReferenceScrapingProducer(),
                isTestScraping ? JobHandler.CreateTestScrapingHandler() : JobHandler.CreateGameHandler(),
                Environment.ProcessorCount);

            Task.Run(() => scrapingWorker.Run()).ContinueWith(
                t => onWorkerFail(t.Exception),
                TaskContinuationOptions.OnlyOnFaulted);
            // Create comparisonWorker threads
            var comparisonWorker = new Worker(JobProducer.CreateComparisonProducer(), JobHandler.CreateComparisonHandler(),
                                              Environment.ProcessorCount);

            Task.Run(() => comparisonWorker.Run()).ContinueWith(
                t => { Console.WriteLine(@"Comparison worker exited with exception: {0}", t.Exception);
                       Environment.Exit(2); },
                TaskContinuationOptions.OnlyOnFaulted);

            Console.WriteLine(@"Worker started as a console application.");
            Console.WriteLine(@"Press any key to quit...");
            Console.ReadKey();
        }
示例#2
0
 public Worker(JobProducer producer, JobHandler handler, int maxConcurrentJobs)
 {
     this._producer              = producer;
     this._handler               = handler;
     this._maxConcurrentJobs     = maxConcurrentJobs;
     this._restartAfterJobsCount = -1;
     this._JobsProcessedCount    = 0;
 }