Ejemplo n.º 1
0
        private void DoJobWork()
        {
            IJob job = JobScheduler.PopJob();

            if (job == null)
            {
                return;
            }

            job.Do();
        }
        protected async Task ExecuteJob(JobContext jobContext, IJob job)
        {
            try
            {
                var reasonToSkip = await job.GetReasonToSkip();

                if (!string.IsNullOrWhiteSpace(reasonToSkip))
                {
                    _logger.LogDebug(reasonToSkip);
                    return;
                }
            }
            catch (Exception exception)
            {
                _errorReportingService.CaptureException(exception);

                var canContinue = CanContinueAfterException(exception);
                if (!canContinue)
                {
                    throw;
                }
            }

            try
            {
                await job.Do(jobContext);
            }
            catch (Exception exception)
            {
                _errorReportingService.CaptureException(exception);

                var canContinue = CanContinueAfterException(exception);
                if (!canContinue)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 3
0
 private void Loop()
 {
     JobProcessor.current = this;
     do
     {
         Util.Filter(delegate
         {
             while (this.status == JobProcessor.Status.Running)
             {
                 if (this.jobCount == 1)
                 {
                     Devcat.Core.WinNative.Thread.SwitchToThread();
                 }
                 if (Interlocked.Decrement(ref this.jobCount) == 0)
                 {
                     this.enqueueEvent.WaitOne();
                     if (this.status != JobProcessor.Status.Running)
                     {
                         break;
                     }
                 }
                 IJob job        = this.jobList.Dequeue();
                 this.currentJob = job;
                 job.StartTick   = Stopwatch.GetTimestamp();
                 if (this.Dequeued != null)
                 {
                     this.Dequeued(this, new EventArgs <IJob>(job));
                 }
                 job.Do();
                 job.EndTick     = Stopwatch.GetTimestamp();
                 this.currentJob = null;
                 if (this.Done != null)
                 {
                     this.Done(this, new EventArgs <IJob>(job));
                 }
             }
             if (this.status == JobProcessor.Status.Closing)
             {
                 while (!this.jobList.Empty)
                 {
                     IJob job2       = this.jobList.Dequeue();
                     this.currentJob = job2;
                     job2.StartTick  = Stopwatch.GetTimestamp();
                     if (this.Dequeued != null)
                     {
                         this.Dequeued(this, new EventArgs <IJob>(job2));
                     }
                     job2.Do();
                     job2.EndTick    = Stopwatch.GetTimestamp();
                     this.currentJob = null;
                     if (this.Done != null)
                     {
                         this.Done(this, new EventArgs <IJob>(job2));
                     }
                 }
                 this.status = JobProcessor.Status.Closed;
             }
         }, delegate(Exception exception)
         {
             if (this.ExceptionFilter != null)
             {
                 try
                 {
                     this.ExceptionFilter(this, new EventArgs <Exception>(exception));
                 }
                 catch
                 {
                 }
             }
         }, delegate(Exception exception)
         {
             if (this.ExceptionOccur != null)
             {
                 try
                 {
                     this.ExceptionOccur(this, new EventArgs <Exception>(exception));
                 }
                 catch
                 {
                 }
             }
         });
     }while (this.status != JobProcessor.Status.Closed);
     this.jobList.Clear();
     this.enqueueEvent.Reset();
 }