コード例 #1
0
        private bool OnJobError(JobExecutionContext context, Exception ex)
        {
            var errorHandler = Volatile.Read(ref JobError);

            if (errorHandler == null)
            {
                return(false);
            }

            var errorArgs = new JobErrorEventArgs(context, ex);

            errorHandler.Invoke(this, errorArgs);

            if (errorArgs.Rethrow)
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
ファイル: JobErrorEventArgs.cs プロジェクト: Workshell/tempus
 internal JobErrorEventArgs(JobExecutionContext context, Exception exception)
 {
     Context   = context;
     Exception = exception;
     Rethrow   = false;
 }
コード例 #3
0
        private void ExecuteJob(IJobFactory factory, IJobRunner runner, ScheduledJob job)
        {
            if (!OnJobStarting(job))
            {
                return;
            }

            runner.Run(async() =>
            {
                if (job.OverlapHandling == OverlapHandling.Skip && _activeJobs.Contains(job))
                {
                    return;
                }

                Lock(job);

                var activeJob = new ActiveJob(job, _cts.Token);

                _activeJobs.Add(activeJob);

                try
                {
                    var context = new JobExecutionContext(this, activeJob.Token);

                    OnJobStarted(context);

                    try
                    {
                        if (!job.IsAnonymous)
                        {
                            using (var scope = factory.CreateScope())
                            {
                                var instance = scope.Create(job.Type);

                                await instance.ExecuteAsync(context);

                                var supportsDispose = typeof(IDisposable).IsAssignableFrom(instance.GetType());

                                if (supportsDispose)
                                {
                                    var disposable = (IDisposable)instance;

                                    disposable.Dispose();
                                }
                            }
                        }
                        else
                        {
                            await job.Handler(context);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (OnJobError(context, ex))
                        {
                            throw;
                        }
                    }

                    OnJobFinished(job);
                }
                finally
                {
                    _activeJobs.Remove(activeJob);
                    Unlock(job);
                }
            });
        }
コード例 #4
0
        private void OnJobStarted(JobExecutionContext context)
        {
            var startedHandler = Volatile.Read(ref JobStarted);

            startedHandler?.Invoke(this, new JobStartedEventArgs(context));
        }
コード例 #5
0
 internal JobStartedEventArgs(JobExecutionContext context)
 {
     Context = context;
 }