예제 #1
0
        private void doJob(JobItem item, bool nextSchedule = true)
        {
            if (item.Pending == true)
            {
                return;
            }

            var type = Type.GetType(item.AssemblyQualifiedName);

            if (type == null)
            {
                _jobItems.Remove(item);
            }
            else
            {
                IJob job = (IJob)type.Assembly.CreateInstance(type.FullName);
                job.DoJob();
                if (nextSchedule)
                {
                    item.Schedule = job.GetScheduleToNextTurn(item.Schedule);
                }
                job.Dispose();
            }
        }
예제 #2
0
파일: Batch.cs 프로젝트: KatoTek/Jobs
        async Task RunJobAsync(IJob job, CancellationToken cancellationToken)
        {
            var jobtype = job.GetType()
                             .FullName;

            job.Log += InvokeLog;
            job.ExceptionThrown += InvokeExceptionThrown;

            try
            {
                InvokeLog($"\t\tJob {jobtype} {STARTED}");
                await job.RunAsync(cancellationToken);
            }
            catch (OperationCanceledException)
            {
                InvokeLog($"\t\tJob {jobtype} {CANCELLED}");
            }
            catch (Exception exception)
            {
                InvokeLog($"\t\tJob {jobtype} {ERRORED}");
                InvokeLog($"{jobtype} Exception{NewLine}{exception.ToText()}");
                InvokeExceptionThrown(job, new JobExceptionThrownEventArguments { Exception = exception, Job = job });
            }
            finally
            {
                job.ExceptionThrown -= InvokeExceptionThrown;
                job.Log -= InvokeLog;

                InvokeLog($"\t\tJob {jobtype} {FINISHED}");

                job.Dispose();
            }
        }