Exemple #1
0
        /// <summary>
        /// 调用结束
        /// </summary>
        /// <param name="context"></param>
        /// <param name="jobException"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default(CancellationToken))
        {
            var model = context.GetQuartzOptions();
            var job   = QuartzExtensions.jobExeInfos.FirstOrDefault(p => p.JobId == model.Id);

            if (job != null)
            {
                job.ExeCount++;
            }
            else
            {
                QuartzExtensions.jobExeInfos.Add(new JobExeInfo()
                {
                    JobId = model.Id, JobName = model.TaskName, ExeCount = 1
                });
            }
            if (jobException != null)
            {
                Console.WriteLine($"{model.TaskName} 发生异常:{jobException.InnerException}");
            }
            model.LastRunTime = DateTime.Now;
            await Task.Run(() =>
            {
                Console.WriteLine($"CustomJobListener JobWasExecuted {context.JobDetail.Description}");
            });
        }
Exemple #2
0
        public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            TaskLogUtil log = new TaskLogUtil();

            log.TaskID    = context.JobDetail.Key.Name;
            log.RunTime   = DateTime.Now;
            log.IsSuccess = 1;
            string result = Convert.ToString(context.Result);

            if (!String.IsNullOrWhiteSpace(result))
            {
                log.IsSuccess = 0;
                log.Result    = result;
            }
            else
            {
                log.Result = "执行完成";
            }
            if (jobException != null)
            {
                log.IsSuccess = 0;
                if (jobException.InnerException != null)
                {
                    log.Result += jobException.ToString();
                }
            }

            TaskHelper.SaveTaskLog(log);
        }
Exemple #3
0
        public Task Execute(IJobExecutionContext context)
        {
            var jobData = context.JobDetail.JobDataMap;
            var uname   = jobData.GetString("uname");
            var upwd    = jobData.GetString("upwd");
            var count   = jobData.GetIntValue("count");

            return(Task.Run(() =>
            {
                try
                {
                    RewardTask rt = new RewardTask();
                    if (count > 0)
                    {
                        rt.JNGAReword(uname, upwd);
                    }
                }
                catch (Exception e)
                {
                    JobExecutionException e2 = new JobExecutionException(e);
                    e2.RefireImmediately = true;
                    jobData.Put("count", count - 1);
                    throw e2;
                }
            }));
        }
 public Task JobWasExecuted(
     IJobExecutionContext context,
     JobExecutionException jobException,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Task.WhenAll(listeners.Select(l => l.JobWasExecuted(context, jobException, cancellationToken))));
 }
Exemple #5
0
        /// <summary>
        /// 执行指定任务
        /// </summary>
        /// <param name="context"></param>
        /// <param name="action"></param>
        public async Task <string> ExecuteJob(IJobExecutionContext context, Func <Task> func)
        {
            string jobHistory = $"【{DateTime.Now}】执行任务【Id:{context.JobDetail.Key.Name},组别:{context.JobDetail.Key.Group}】";

            try
            {
                var s = context.Trigger.Key.Name;
                //记录Job时间
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                await func();//执行任务

                stopwatch.Stop();
                jobHistory += $",【执行成功】,完成时间:{stopwatch.Elapsed.TotalMilliseconds:00}毫秒";
                //SerilogServer.WriteLog(context.Trigger.Key.Name.Replace("-", ""), $"{context.Trigger.Key.Name}定时任务运行一切OK", "任务结束");
            }
            catch (Exception ex)
            {
                _ = new JobExecutionException(ex)
                {
                    //true  是立即重新执行任务
                    RefireImmediately = true
                };
                //SerilogServer.WriteErrorLog(context.Trigger.Key.Name.Replace("-", ""), $"{context.Trigger.Key.Name}任务运行异常", ex);

                jobHistory += $",【执行失败】,异常日志:{ex.Message}";
            }

            Console.Out.WriteLine(jobHistory);
            return(jobHistory);
        }
 public void WriteException(Activity?activity, JobExecutionException exception)
 {
     if (activity != null && diagnosticListener.IsEnabled(name))
     {
         diagnosticListener.Write(name + ".Exception", exception);
     }
 }
Exemple #7
0
 public Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException,
                            CancellationToken cancellationToken = default(CancellationToken))
 {
     _logger.LogInformation(Constants.BypassFiltersEventId, null, "Finished job {0} at {1}.",
                            context.JobDetail.JobType.Name, DateTime.UtcNow);
     return(Task.FromResult(0));
 }
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                // 1. 获取Task 基本信息及 Task 配置的其他参数,任务启动时会读取配置文件节点的值传递过来
                TaskModel task = QuartzHelper.GetTaskDetail(context);
                // 2. 记录Task 运行状态数据库
                DbLogHelper.WriteRunInfo(task.TaskName + " 开始", task.TaskID.ToString(), "");

                // 3. 开始执行相关任务
                LogHelper.WriteLog(task.TaskName + ",当前系统时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

                Thread.Sleep(9000);

                // 4. 记录Task 运行状态数据库
                DbLogHelper.WriteRunInfo(task.TaskName + " 结束", task.TaskID.ToString(), "成功执行");
            }
            catch (Exception ex)
            {
                JobExecutionException e2 = new JobExecutionException(ex);
                // 记录异常到数据库和 log 文件中。
                DbLogHelper.WriteErrorInfo(ex);
                //true  是立即重新执行任务
                e2.RefireImmediately = true;
            }
        }
Exemple #9
0
 public void Execute(IJobExecutionContext context)
 {
     try
     {
         string   LogDir = FileHelper.GetAbsolutePath("/Logs");
         string[] files  = Directory.GetFiles(LogDir, "*.*", SearchOption.AllDirectories);
         FileInfo fi     = null;
         foreach (var item in files)
         {
             fi = new FileInfo(item);
             if ((DateTime.Now - fi.CreationTime).TotalDays > LogConfig.Days)
             {
                 try
                 {
                     File.Delete(item);
                 }
                 catch { }
             }
         }
     }
     catch (Exception ex)
     {
         JobExecutionException e2 = new JobExecutionException(ex);
         LogHelper.WriteLog("日志清理任务异常", ex);
         //1.立即重新执行任务
         e2.RefireImmediately = true;
     }
 }
		/// <summary>
		/// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" />
		/// fires that is associated with the <see cref="IJob" />.
		/// <para>
		/// The implementation may wish to set a  result object on the
		/// JobExecutionContext before this method exits.  The result itself
		/// is meaningless to Quartz, but may be informative to
		/// <see cref="IJobListener" />s or
		/// <see cref="ITriggerListener" />s that are watching the job's
		/// execution.
		/// </para>
		/// </summary>
		/// <param name="context">Execution context.</param>
		public virtual void Execute(IJobExecutionContext context)
		{
			JobKey jobKey = context.JobDetail.Key;
			log.InfoFormat("---{0} executing at {1}", jobKey, System.DateTime.Now.ToString("r"));
			
			// a contrived example of an exception that
			// will be generated by this job due to a 
			// divide by zero error
			try
			{
				int zero = 0;
				int calculation = 4815 / zero;
			}
			catch (System.Exception e)
			{
				log.Info("--- Error in job!");
				JobExecutionException e2 = new JobExecutionException(e);
				// Quartz will automatically unschedule
				// all triggers associated with this job
				// so that it does not run again
				e2.UnscheduleAllTriggers = true;
				throw e2;
			}
			
			log.InfoFormat("---{0} completed at {1}", jobKey, System.DateTime.Now.ToString("r"));
		}
Exemple #11
0
 public async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default)
 {
     await Task.Run(() =>
     {
         Console.WriteLine("this is jobExecuted");
     });
 }
Exemple #12
0
        public virtual void JobWasExecuted(IJobExecutionContext inContext, JobExecutionException inException)
        {
            log.Info("Job1Listener says: Job was executed.");

            // Simple job #2
            IJobDetail job2 = JobBuilder.Create<SimpleJob2>()
                .WithIdentity("job2")
                .Build();

            ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity("job2Trigger")
                .StartNow()
                .Build();

            try
            {
                // schedule the job to run!
                inContext.Scheduler.ScheduleJob(job2, trigger);
            }
            catch (SchedulerException e)
            {
                log.Warn("Unable to schedule job2!");
                Console.Error.WriteLine(e.StackTrace);
            }
        }
Exemple #13
0
 public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
 {
     if (AfterExecuted != null)
     {
         AfterExecuted(context, jobException);
     }
 }
Exemple #14
0
		/// <summary>
		/// Called by the <see cref="IScheduler" /> when a Trigger" />
		/// fires that is associated with the <see cref="IJob" />.
		/// </summary>
		public virtual void Execute(IJobExecutionContext context)
		{
			JobKey jobKey = context.JobDetail.Key;
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            int denominator = dataMap.GetInt("denominator");
            log.InfoFormat("{0} with denominator {1}", "---" + jobKey + " executing at " + DateTime.Now, denominator);


			// a contrived example of an exception that
			// will be generated by this job due to a 
            // divide by zero error (only on first run)
			try
			{
                int calculation = 4815 / denominator;
			}
			catch (Exception e)
			{
				log.Info("--- Error in job!");
				JobExecutionException e2 = new JobExecutionException(e);


                // fix denominator so the next time this job run
                // it won't fail again
                dataMap.Put("denominator", "1");

				// this job will refire immediately
				e2.RefireImmediately = true;
				throw e2;
			}
			
			log.InfoFormat("---{0} completed at {1}", jobKey, DateTime.Now.ToString("r"));
		}
        public override Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default)
        {
            if (!context.Trigger.JobDataMap.ContainsKey(JobInfoModel.INTANCE_GUID_NAME))
            {
                Debug.Assert(false, "Should never happen");
                _logger.LogWarning("We have task without JobInfoModel.INTANCE_GUID_NAME");
                return(Task.CompletedTask);
            }

            var taskId = (Guid)context.Trigger.JobDataMap[JobInfoModel.INTANCE_GUID_NAME];

            TaskCompletionSource <object> complitionSource;

            if (_mapJobCompletion.TryRemove((Guid)context.Trigger.JobDataMap[JobInfoModel.INTANCE_GUID_NAME], out complitionSource))
            {
                if (null == jobException)
                {
                    complitionSource.SetResult(context.Result);
                }
                else
                {
                    complitionSource.SetException(jobException);
                }
            }
            else
            {
                //we have no one to talk to
                _logger.LogDebug($"No waiters for the Task Instance {taskId}");
            }

            return(Task.CompletedTask);
        }
 /// <summary>
 /// Called by the <see cref="IScheduler"/> after a <see cref="IJobDetail"/>
 /// has been executed, and be for the associated <see cref="ITrigger"/>'s
 /// <see cref="IOperableTrigger.Triggered"/> method has been called.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="jobException"></param>
 /// <param name="cancellationToken">The cancellation instruction.</param>
 public virtual Task JobWasExecuted(
     IJobExecutionContext context,
     JobExecutionException jobException,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(TaskUtil.CompletedTask);
 }
Exemple #17
0
        public override async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default)
        {
            string   group       = context.JobDetail.Key.Group;
            string   name        = context.JobDetail.Key.Name;
            DateTime fireTimeUtc = TimeZoneInfo.ConvertTimeFromUtc(context.FireTimeUtc.DateTime, TimeZoneInfo.Local);

            DateTime?nextFireTimeUtc = null;

            if (context.NextFireTimeUtc != null)
            {
                nextFireTimeUtc = TimeZoneInfo.ConvertTimeFromUtc(context.NextFireTimeUtc.Value.DateTime, TimeZoneInfo.Local);
            }

            if (!JobHelper.IsBaseJob(group, name))
            {
                //更新任务运行情况
                await _jobRepository.UpdateExecuteAsync(group, name, fireTimeUtc, nextFireTimeUtc);

                //记录运行日志
                double totalSeconds = context.JobRunTime.TotalSeconds;
                bool   succ         = true;
                string exception    = string.Empty;
                if (jobException != null)
                {
                    succ      = false;
                    exception = jobException.ToString();
                }

                JobRunLog log = new JobRunLog(group, name, totalSeconds, fireTimeUtc, succ, exception);
                await _jobRunLogRepository.InsertAsync(log);
            }
        }
Exemple #18
0
        /// <summary>
        /// Called by the <see cref="IScheduler" /> when a <see cref="Trigger" />
        /// fires that is associated with the <see cref="IJob" />.
        /// <p>
        /// The implementation may wish to set a  result object on the
        /// JobExecutionContext before this method exits.  The result itself
        /// is meaningless to Quartz, but may be informative to
        /// <see cref="JobListeners" /> or
        /// <see cref="TriggerListeners" /> that are watching the job's
        /// execution.
        /// </p>
        /// </summary>
        /// <param name="context">Execution context.</param>
        public virtual void Execute(JobExecutionContext context)
        {
            System.String jobName = context.JobDetail.FullName;
            _log.Info(string.Format("---{0} executing at {1}", jobName, System.DateTime.Now.ToString("r")));

            // a contrived example of an exception that
            // will be generated by this job due to a
            // divide by zero error
            try
            {
                int zero        = 0;
                int calculation = 4815 / zero;
            }
            catch (System.Exception e)
            {
                _log.Info("--- Error in job!");
                JobExecutionException e2 = new JobExecutionException(e);
                // Quartz will automatically unschedule
                // all triggers associated with this job
                // so that it does not run again
                e2.UnscheduleAllTriggers = true;
                throw e2;
            }

            _log.Info(string.Format("---{0} completed at {1}", jobName, System.DateTime.Now.ToString("r")));
        }
        public virtual Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            IJobExecutionContext temp;

            executingJobs.TryRemove(((IOperableTrigger)context.Trigger).FireInstanceId, out temp);
            return(TaskUtil.CompletedTask);
        }
Exemple #20
0
        public override async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default)
        {
            string group = context.JobDetail.Key.Group;
            string name  = context.JobDetail.Key.Name;


            if (!JobHelper.IsBaseJob(group, name))
            {
                DateTime fireTimeUtc = TimeZoneInfo.ConvertTimeFromUtc(context.FireTimeUtc.DateTime, TimeZoneInfo.Local);

                DateTime?nextFireTimeUtc = null;
                if (context.NextFireTimeUtc != null)
                {
                    nextFireTimeUtc = TimeZoneInfo.ConvertTimeFromUtc(context.NextFireTimeUtc.Value.DateTime, TimeZoneInfo.Local);
                }

                //更新任务运行情况
                await _jobService.UpdateExecuteAsync(group, name, fireTimeUtc, nextFireTimeUtc);

                ////记录运行日志
                //double totalSeconds = context.JobRunTime.TotalSeconds;
                //bool succ = true;
                //string exception = string.Empty;
                //if (jobException != null)
                //{
                //    succ = false;
                //    exception = jobException.ToString();
                //}

                //JobRunLogEntity log = new JobRunLogEntity() { JobGroup = group, JobName = name, StartTime = fireTimeUtc, Succ = succ, Exception = exception };
                //await _jobRunLogService.InsertAsync(log);
            }
        }
        //runs after the job is executed
        public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            string itemID      = dataMap.GetString(SitecronConstants.FieldNames.ItemID);
            bool   archiveItem = false;

            if (!string.IsNullOrEmpty(dataMap.GetString(SitecronConstants.FieldNames.ArchiveAfterExecution)) && dataMap.GetString(SitecronConstants.FieldNames.ArchiveAfterExecution) == "1")
            {
                archiveItem = true;
            }

            Log.Info(string.Format("Sitecron - Job {0} in group {1} was executed. (ItemID: {2} Archive:{3})", context.JobDetail.Key.Name, context.JobDetail.Key.Group, itemID, archiveItem.ToString()), this);

            if (archiveItem && !string.IsNullOrEmpty(itemID))
            {
                string contextDbName = Settings.GetSetting(SitecronConstants.SettingsNames.SiteCronContextDB);
                if (contextDbName != SitecronConstants.SitecoreDatabases.Master)
                {
                    Database contextDb = Factory.GetDatabase(contextDbName);

                    if (contextDb != null)
                    {
                        ArchiveItem(contextDb, itemID);
                    }
                }
                Database masterDb = Factory.GetDatabase(SitecronConstants.SitecoreDatabases.Master);
                if (masterDb != null)
                {
                    ArchiveItem(masterDb, itemID);
                }
            }
        }
Exemple #22
0
        /// <summary>
        /// Called by the <see cref="IScheduler" /> when a Trigger" />
        /// fires that is associated with the <see cref="IJob" />.
        /// </summary>
        public virtual Task Execute(IJobExecutionContext context)
        {
            JobKey     jobKey  = context.JobDetail.Key;
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            int denominator = dataMap.GetInt("denominator");

            Console.WriteLine("{0} with denominator {1}", "---" + jobKey + " executing at " + DateTime.Now, denominator);

            // a contrived example of an exception that
            // will be generated by this job due to a
            // divide by zero error (only on first run)
            try
            {
                int calculation = 4815 / denominator;
            }
            catch (Exception e)
            {
                Console.WriteLine("--- Error in job!");
                JobExecutionException e2 = new JobExecutionException(e);

                // fix denominator so the next time this job run
                // it won't fail again
                dataMap.Put("denominator", "1");

                // this job will refire immediately
                e2.RefireImmediately = true;
                throw e2;
            }

            Console.WriteLine("---{0} completed at {1:r}", jobKey, DateTime.Now);
            return(Task.CompletedTask);
        }
Exemple #23
0
        /// <summary>
        /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" />
        /// fires that is associated with the <see cref="IJob" />.
        /// <para>
        /// The implementation may wish to set a  result object on the
        /// JobExecutionContext before this method exits.  The result itself
        /// is meaningless to Quartz, but may be informative to
        /// <see cref="IJobListener" />s or
        /// <see cref="ITriggerListener" />s that are watching the job's
        /// execution.
        /// </para>
        /// </summary>
        /// <param name="context">Execution context.</param>
        public virtual Task Execute(IJobExecutionContext context)
        {
            JobKey jobKey = context.JobDetail.Key;

            log.InfoFormat("---{0} executing at {1}", jobKey, DateTime.Now.ToString("r"));

            // a contrived example of an exception that
            // will be generated by this job due to a
            // divide by zero error
            try
            {
                int zero        = 0;
                int calculation = 4815 / zero;
            }
            catch (Exception e)
            {
                log.Info("--- Error in job!");
                JobExecutionException e2 = new JobExecutionException(e);
                // Quartz will automatically unschedule
                // all triggers associated with this job
                // so that it does not run again
                e2.UnscheduleAllTriggers = true;
                throw e2;
            }

            log.InfoFormat("---{0} completed at {1}", jobKey, DateTime.Now.ToString("r"));
            return(Task.CompletedTask);
        }
Exemple #24
0
 public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
 {
     foreach (IJobListener jl in listeners)
     {
         jl.JobWasExecuted(context, jobException);
     }
 }
        public Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken)
        {
            JobKey jobKey = context.JobDetail.Key;
            Task   task   = Task.Run(() => Console.WriteLine("{0} finished at {1} ", jobKey, DateTime.Now.Second));

            return(task);
        }
 void IJobListener.JobWasExecuted(JobExecutionContext context, JobExecutionException jobException)
 {
     if (jobException != null)
     {
         ErrorLogger.WriteErrorLog(DateTime.Now, jobException);
     }
 }
Exemple #27
0
        public async Task TestJobFailedMessage()
        {
            JobExecutionException ex = new JobExecutionException("test error");
            await plugin.JobWasExecuted(CreateJobExecutionContext(), ex);

            Assert.That(plugin.WarnMessages.Count, Is.EqualTo(1));
        }
Exemple #28
0
        /// <summary>
        /// 执行指定任务
        /// </summary>
        /// <param name="context"></param>
        /// <param name="action"></param>
        public async Task <string> ExecuteJob(IJobExecutionContext context, Func <Task> job)
        {
            string jobHistory = $"Run Job [Id:{context.JobDetail.Key.Name},Group:{context.JobDetail.Key.Group}]";

            try
            {
                var s = context.Trigger.Key.Name;
                //记录Job时间
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                //执行任务
                await job();

                stopwatch.Stop();
                jobHistory += $", Succeed , Elapsed:{stopwatch.Elapsed.TotalMilliseconds} ms";
            }
            catch (Exception ex)
            {
                JobExecutionException e2 = new JobExecutionException(ex);
                //true  是立即重新执行任务
                e2.RefireImmediately = true;
                jobHistory          += $", Fail ,Exception:{ex.Message}";
            }

            return(jobHistory);
        }
Exemple #29
0
 public Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException,
                            CancellationToken cancellationToken = new CancellationToken())
 {
     //執行前
     Console.WriteLine("after");
     return(Task.Delay(0));
 }
Exemple #30
0
        public virtual async Task JobWasExecuted(IJobExecutionContext inContext, JobExecutionException inException)
        {
            log.Info("Job1Listener says: Job was executed.");

            // Simple job #2
            IJobDetail job2 = JobBuilder.Create <SimpleJob2>()
                              .WithIdentity("job2")
                              .Build();

            ITrigger trigger = TriggerBuilder.Create()
                               .WithIdentity("job2Trigger")
                               .StartNow()
                               .Build();

            try
            {
                // schedule the job to run!
                await inContext.Scheduler.ScheduleJob(job2, trigger);
            }
            catch (SchedulerException e)
            {
                log.Warn("Unable to schedule job2!");
                Console.Error.WriteLine(e.StackTrace);
            }
        }
Exemple #31
0
        /// <summary>
        /// Called by the <see cref="IScheduler" /> when a Trigger" />
        /// fires that is associated with the <see cref="IJob" />.
        /// </summary>
        public virtual void Execute(IJobExecutionContext context)
        {
            JobKey jobKey = context.JobDetail.Key;

            log.InfoFormat("---{0} executing at {1}", jobKey, DateTime.Now.ToString("r"));

            // a contrived example of an exception that
            // will be generated by this job due to a
            // divide by zero error
            try
            {
                int zero        = 0;
                int calculation = 4815 / zero;
            }
            catch (Exception e)
            {
                log.Info("--- Error in job!");
                JobExecutionException e2 = new JobExecutionException(e);
                // this job will refire immediately
                e2.RefireImmediately = true;
                throw e2;
            }

            log.InfoFormat("---{0} completed at {1}", jobKey, DateTime.Now.ToString("r"));
        }
Exemple #32
0
 public async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default)
 {
     await Task.Run(() => {
         Console.WriteLine();
         Console.WriteLine($"[{DateTime.Now}]MyJobListener 作业执行完毕 {context.JobDetail.Description}");
     }, cancellationToken);
 }
 /// <summary>
 /// Called by the <see cref="IScheduler" /> after a <see cref="IJobDetail" />
 /// has been executed, and be for the associated <see cref="ITrigger" />'s
 /// <see cref="IOperableTrigger.Triggered" /> method has been called.
 /// </summary>
 public virtual Task JobWasExecuted(
     IJobExecutionContext context,
     JobExecutionException jobException,
     CancellationToken cancellationToken)
 {
     return(Delegate.InsertJobHistoryEntry(context, jobException, cancellationToken));
 }
Exemple #34
0
 /// <summary>
 /// Jobs the was executed.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="jobException">The job exception.</param>
 public void JobWasExecuted(JobExecutionContext context, JobExecutionException jobException)
 {
     if (jobException != null)
     {
         Inject();
         Logger.Log(LogSeverity.Error, GetType().ToString(), jobException);
     }
 }
        /// <summary>
        /// Called by the <see cref="T:Quartz.IScheduler" /> after a <see cref="T:Quartz.IJobDetail" />
        /// has been executed, and be for the associated <see cref="T:Quartz.ITrigger" />'s
        /// <see cref="M:Quartz.Spi.IOperableTrigger.Triggered(Quartz.ICalendar)" /> method has been called.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="jobException"></param>
        public override void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            base.JobWasExecuted(context, jobException);

            if (jobException != null)
            {
                this.logger.Error(jobException.Message, jobException);
            }

            this.bmwCall.Complete(jobException == null);
        }
        public void TestJobFailedMessage()
        {
            // arrange
            mockLog.Stub(log => log.IsWarnEnabled).Return(true);

            // act
            JobExecutionException ex = new JobExecutionException("test error");
            plugin.JobWasExecuted(CreateJobExecutionContext(), ex);

            // assert
            mockLog.AssertWasCalled(log => log.Warn(Arg<string>.Is.Anything, Arg<Exception>.Is.Anything));
        }
        /// <summary>
        /// Called by the <see cref="IScheduler"/> when a <see cref="ITrigger"/>
        /// fires that is associated with the <see cref="IJob"/>.
        /// </summary>
        /// <param name="context">The execution context.</param>
        /// <remarks>
        /// The implementation may wish to set a  result object on the
        /// JobExecutionContext before this method exits.  The result itself
        /// is meaningless to Quartz, but may be informative to
        /// <see cref="IJobListener"/>s or
        /// <see cref="ITriggerListener"/>s that are watching the job's
        /// execution.
        /// </remarks>
        public void Execute(IJobExecutionContext context)
        {
            LaunchCount++;
            if (ThrowsException)
            {
                JobExecutionException toThrow = new JobExecutionException("test exception");
                toThrow.RefireImmediately = Refire;
                toThrow.UnscheduleFiringTrigger = UnscheduleFiringTrigger;
                toThrow.UnscheduleAllTriggers = UnscheduleAllTriggers;

                throw toThrow;
            }
        }
 public override void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
 {
     if (Interlocked.Increment(ref jobExCount) == jobExecutionCountToSyncAfter)
     {
         try
         {
             barrier.Set();
         }
         catch (Exception e)
         {
             Console.Error.WriteLine(e.ToString());
             throw new AssertionException("Await on barrier was interrupted: " + e);
         }
     }
 }
        public void JobWasExecuted(JobExecutionContext context, JobExecutionException jobException)
        {
            if (jobException == null)
                return; 

            var retryableJob = context.JobInstance as IRetryableJob;
            if (retryableJob == null)
                return; 

            int numberTries = context.JobDetail.JobDataMap.GetIntValue(NumberTriesJobDataMapKey);
            if (numberTries >= retryableJob.MaxNumberTries)
                return; // Max number tries reached

            // Schedule next try
            ScheduleRetryableJob(context, retryableJob);
        }
        public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            JobExecutionData data = context.Get("JobExecutionData") as JobExecutionData;
            if (data != null)
            {
                data.JobEndTime = DateTime.Now;
                lock (_Data)
                {
                    if (_Data.Count > _Capacity)
                    {
                        _Data.RemoveAt(0);
                    }
                    _Data.Add(data);

                }
            }
        }
        public async Task InsertJobHistoryEntry(IJobExecutionContext context, JobExecutionException jobException)
        {
            var sql = AdoJobStoreUtil.ReplaceTablePrefix(SqlInsertJobExecuted, tablePrefix, null);
            using (var connection = GetConnection(IsolationLevel.ReadUncommitted))
            {
                using (var command = Delegate.PrepareCommand(connection, sql))
                {
                    Delegate.AddCommandParameter(command, "schedulerName", context.Scheduler.SchedulerName);
                    Delegate.AddCommandParameter(command, "instanceName", context.Scheduler.SchedulerInstanceId);
                    Delegate.AddCommandParameter(command, "jobName", context.JobDetail.Key.Name);
                    Delegate.AddCommandParameter(command, "jobGroup", context.JobDetail.Key.Group);
                    Delegate.AddCommandParameter(command, "triggerName", context.Trigger.Key.Name);
                    Delegate.AddCommandParameter(command, "triggerGroup", context.Trigger.Key.Group);
                    Delegate.AddCommandParameter(command, "scheduledTime", Delegate.GetDbDateTimeValue(context.ScheduledFireTimeUtc));
                    Delegate.AddCommandParameter(command, "firedTime", Delegate.GetDbDateTimeValue(context.FireTimeUtc));
                    Delegate.AddCommandParameter(command, "runTime", Delegate.GetDbTimeSpanValue(context.JobRunTime));
                    Delegate.AddCommandParameter(command, "error", Delegate.GetDbBooleanValue(jobException != null));
                    Delegate.AddCommandParameter(command, "errorMessage", jobException?.ToString());

                    await command.ExecuteNonQueryAsync().ConfigureAwait(false);
                    connection.Commit();
                }
            }
        }
Exemple #42
0
        /// <summary>
        /// Called by the <see cref="IScheduler" /> when a Trigger" />
        /// fires that is associated with the <see cref="IJob" />.
        /// </summary>
        public virtual void Execute(IJobExecutionContext context)
        {
            JobKey jobKey = context.JobDetail.Key;
            log.InfoFormat("---{0} executing at {1}", jobKey, DateTime.Now.ToString("r"));

            // a contrived example of an exception that
            // will be generated by this job due to a
            // divide by zero error
            try
            {
                int zero = 0;
                int calculation = 4815 / zero;
            }
            catch (Exception e)
            {
                log.Info("--- Error in job!");
                JobExecutionException e2 = new JobExecutionException(e);
                // this job will refire immediately
                e2.RefireImmediately = true;
                throw e2;
            }

            log.InfoFormat("---{0} completed at {1}", jobKey, DateTime.Now.ToString("r"));
        }
        public void JobWasExecuted(JobExecutionContext context, JobExecutionException jobException)
        {
            if (!ShouldDispatch(context))
            {
                return;
            }

            foreach (IJobListener jl in listeners)
            {
                jl.JobWasExecuted(context, jobException);
            }
        }
 public Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
 {
     return Task.WhenAll(listeners.Select(l => l.JobWasExecuted(context, jobException)));
 }
        /// <summary>
        /// Called by the <see cref="IScheduler" /> after a <see cref="IJobDetail" />
        /// has been executed, and be for the associated <see cref="ITrigger" />'s
        /// <see cref="IOperableTrigger.Triggered" /> method has been called.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="jobException"></param>
        public virtual void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            ITrigger trigger = context.Trigger;

            object[] args;

            if (jobException != null)
            {
                string errMsg = jobException.Message;
                args =
                    new object[]
                        {
                            context.JobDetail.Key.Name, context.JobDetail.Key.Group, SystemTime.UtcNow(), trigger.Key.Name, trigger.Key.Group,
                            trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), context.RefireCount, errMsg
                        };
            }
            else
            {
                

                string result = Convert.ToString(context.Result, CultureInfo.InvariantCulture);
                args =
                    new object[]
                        {
                            context.JobDetail.Key.Name, context.JobDetail.Key.Group, SystemTime.UtcNow(), trigger.Key.Name, trigger.Key.Group,
                            trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), context.RefireCount, result
                        };
            }
        }
        public override void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            JobKey sj;
            chainLinks.TryGetValue(context.JobDetail.Key, out sj);

            if (sj == null)
            {
                return;
            }

            Log.Info(string.Format(CultureInfo.InvariantCulture, "Job '{0}' will now chain to Job '{1}'", context.JobDetail.Key, sj));

            try
            {
                context.Scheduler.TriggerJob(sj);
            }
            catch (SchedulerException se)
            {
                Log.Error(string.Format(CultureInfo.InvariantCulture, "Error encountered during chaining to Job '{0}'", sj), se);
            }
        }
 public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
 {
     Write("{0} -- {1} -- Job ({2}) was executed", Name, DateTime.Now, context.JobDetail.Key);
 }
Exemple #48
0
		/// <summary>
		/// This method has to be implemented in order that starting of the thread causes the object's
		/// run method to be called in that separately executing thread.
		/// </summary>
		public virtual void Run()
		{
            try
            {
                Trigger trigger = jec.Trigger;
                JobDetail jobDetail = jec.JobDetail;
                do
                {
                    JobExecutionException jobExEx = null;
                    IJob job = jec.JobInstance;

                    try
                    {
                        Begin();
                    }
                    catch (SchedulerException se)
                    {
                        qs.NotifySchedulerListenersError(
                            string.Format(CultureInfo.InvariantCulture, "Error executing Job ({0}: couldn't begin execution.", jec.JobDetail.FullName),
                            se);
                        break;
                    }

                    // notify job & trigger listeners...
                    SchedulerInstruction instCode;
                    try
                    {
                        if (!NotifyListenersBeginning(jec))
                        {
                            break;
                        }
                    }
                    catch (VetoedException)
                    {
                        try
                        {
                            instCode = trigger.ExecutionComplete(jec, null);
                            try
                            {
                                qs.NotifyJobStoreJobVetoed(schdCtxt, trigger, jobDetail, instCode);
                            }
                            catch (JobPersistenceException)
                            {
                                VetoedJobRetryLoop(trigger, jobDetail, instCode);
                            }
                            Complete(true);
                        }
                        catch (SchedulerException se)
                        {
                            qs.NotifySchedulerListenersError(
                                string.Format(CultureInfo.InvariantCulture, "Error during veto of Job ({0}: couldn't finalize execution.",
                                              jec.JobDetail.FullName), se);
                        }
                        break;
                    }

                    DateTime startTime = DateTime.UtcNow;
                    DateTime endTime;

                    // Execute the job
                    try
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("Calling Execute on job " + jobDetail.FullName);
                        }
                        job.Execute(jec);
                        endTime = DateTime.UtcNow;
                    }
                    catch (JobExecutionException jee)
                    {
                        endTime = DateTime.UtcNow;
                        jobExEx = jee;
                        log.Info(string.Format(CultureInfo.InvariantCulture, "Job {0} threw a JobExecutionException: ", jobDetail.FullName), jobExEx);
                    }
                    catch (Exception e)
                    {
                        endTime = DateTime.UtcNow;
                        log.Error(string.Format(CultureInfo.InvariantCulture, "Job {0} threw an unhandled Exception: ", jobDetail.FullName), e);
                        SchedulerException se = new SchedulerException("Job threw an unhandled exception.", e);
                        se.ErrorCode = SchedulerException.ErrorJobExecutionThrewException;
                        qs.NotifySchedulerListenersError(
                            string.Format(CultureInfo.InvariantCulture, "Job ({0} threw an exception.", jec.JobDetail.FullName), se);
                        jobExEx = new JobExecutionException(se, false);
                        jobExEx.ErrorCode = JobExecutionException.ErrorJobExecutionThrewException;
                    }

                    jec.JobRunTime = endTime - startTime;

                    // notify all job listeners
                    if (!NotifyJobListenersComplete(jec, jobExEx))
                    {
                        break;
                    }

                    instCode = SchedulerInstruction.NoInstruction;

                    // update the trigger
                    try
                    {
                        instCode = trigger.ExecutionComplete(jec, jobExEx);
                        if (log.IsDebugEnabled)
                        {
                            log.Debug(string.Format(CultureInfo.InvariantCulture, "Trigger instruction : {0}", instCode));
                        }
                    }
                    catch (Exception e)
                    {
                        // If this happens, there's a bug in the trigger...
                        SchedulerException se = new SchedulerException("Trigger threw an unhandled exception.", e);
                        se.ErrorCode = SchedulerException.ErrorTriggerThrewException;
                        qs.NotifySchedulerListenersError("Please report this error to the Scheduler developers.", se);
                    }

                    // notify all trigger listeners
                    if (!NotifyTriggerListenersComplete(jec, instCode))
                    {
                        break;
                    }
                    // update job/trigger or re-Execute job
                    if (instCode == SchedulerInstruction.ReExecuteJob)
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("Rescheduling trigger to reexecute");
                        }
                        jec.IncrementRefireCount();
                        try
                        {
                            Complete(false);
                        }
                        catch (SchedulerException se)
                        {
                            qs.NotifySchedulerListenersError(
                                string.Format(CultureInfo.InvariantCulture, "Error executing Job ({0}: couldn't finalize execution.",
                                              jec.JobDetail.FullName), se);
                        }
                        continue;
                    }

                    try
                    {
                        Complete(true);
                    }
                    catch (SchedulerException se)
                    {
                        qs.NotifySchedulerListenersError(
                            string.Format(CultureInfo.InvariantCulture, "Error executing Job ({0}: couldn't finalize execution.",
                                          jec.JobDetail.FullName), se);
                        continue;
                    }

                    try
                    {
                        qs.NotifyJobStoreJobComplete(schdCtxt, trigger, jobDetail, instCode);
                    }
                    catch (JobPersistenceException jpe)
                    {
                        qs.NotifySchedulerListenersError(
                            string.Format(CultureInfo.InvariantCulture, "An error occured while marking executed job complete. job= '{0}'",
                                          jobDetail.FullName), jpe);
                        if (!CompleteTriggerRetryLoop(trigger, jobDetail, instCode))
                        {
                        }
                        return;
                    }

                    break;
                } while (true);

            }
		    finally
            {
                jobRunShellFactory.ReturnJobRunShell(this);
            }
		}
 /// <summary>
 /// Called by the <see cref="IScheduler"/> after a <see cref="JobDetail"/>
 /// has been executed, and be for the associated <see cref="Trigger"/>'s
 /// <see cref="Trigger.Triggered"/> method has been called.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="jobException"></param>
 public virtual void JobWasExecuted(JobExecutionContext context, JobExecutionException jobException)
 {
 }
        public override async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            JobKey sj;
            chainLinks.TryGetValue(context.JobDetail.Key, out sj);

            if (sj == null)
            {
                return;
            }

            Log.Info($"Job '{context.JobDetail.Key}' will now chain to Job '{sj}'");

            try
            {
                await context.Scheduler.TriggerJob(sj).ConfigureAwait(false);
            }
            catch (SchedulerException se)
            {
                Log.ErrorException($"Error encountered during chaining to Job '{sj}'", se);
            }
        }
        public override void JobWasExecuted(JobExecutionContext context, JobExecutionException jobException)
        {
            Key sj = (Key) chainLinks[context.JobDetail.Key];

            if (sj == null)
            {
                return;
            }

            Log.Info(string.Format(CultureInfo.InvariantCulture, "Job '{0}' will now chain to Job '{1}'", context.JobDetail.FullName, sj));

            try
            {
                if (context.JobDetail.Volatile || context.Trigger.Volatile)
                {
                    context.Scheduler.TriggerJobWithVolatileTrigger(sj.Name, sj.Group);
                }
                else
                {
                    context.Scheduler.TriggerJob(sj.Name, sj.Group);
                }
            }
            catch (SchedulerException se)
            {
                Log.Error(string.Format(CultureInfo.InvariantCulture, "Error encountered during chaining to Job '{0}'", sj), se);
            }
        }
 public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
 {
     foreach (IJobListener jl in listeners)
     {
         jl.JobWasExecuted(context, jobException);
     }
 }
Exemple #53
0
        /// <summary>
        /// Notifies the job listeners that job was executed.
        /// </summary>
        /// <param name="jec">The jec.</param>
        /// <param name="je">The je.</param>
        public virtual async Task NotifyJobListenersWasExecuted(IJobExecutionContext jec, JobExecutionException je)
        {
            // build a list of all job listeners that are to be notified...
            IEnumerable<IJobListener> listeners = BuildJobListenerList();

            // notify all job listeners
            foreach (IJobListener jl in listeners)
            {
                if (!MatchJobListener(jl, jec.JobDetail.Key))
                {
                    continue;
                }
                try
                {
                    await jl.JobWasExecuted(jec, je).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    SchedulerException se = new SchedulerException($"JobListener '{jl.Name}' threw exception: {e.Message}", e);
                    throw se;
                }
            }
        }
 public void JobWasExecuted(IJobExecutionContext context,
                            JobExecutionException jobException)
 {
     jobsCompletedCount.Increment();
 }
 public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
 {
 }
Exemple #56
0
        /// <summary>
        /// This method has to be implemented in order that starting of the thread causes the object's
        /// run method to be called in that separately executing thread.
        /// </summary>
        public virtual void Run()
        {
            qs.AddInternalSchedulerListener(this);

            try
            {
                IOperableTrigger trigger = (IOperableTrigger) jec.Trigger;
                IJobDetail jobDetail = jec.JobDetail;
                do
                {
                    JobExecutionException jobExEx = null;
                    IJob job = jec.JobInstance;

                    try
                    {
                        Begin();
                    }
                    catch (SchedulerException se)
                    {
                        qs.NotifySchedulerListenersError(
                            string.Format(CultureInfo.InvariantCulture, "Error executing Job ({0}: couldn't begin execution.", jec.JobDetail.Key),
                            se);
                        break;
                    }

                    // notify job & trigger listeners...
                    SchedulerInstruction instCode;
                    try
                    {
                        if (!NotifyListenersBeginning(jec))
                        {
                            break;
                        }
                    }
                    catch (VetoedException)
                    {
                        try
                        {
                            instCode = trigger.ExecutionComplete(jec, null);
                            try
                            {
                                qs.NotifyJobStoreJobVetoed(trigger, jobDetail, instCode);
                            }
                            catch (JobPersistenceException)
                            {
                                VetoedJobRetryLoop(trigger, jobDetail, instCode);
                            }

                            // Even if trigger got vetoed, we still needs to check to see if it's the trigger's finalized run or not.
                            if (jec.Trigger.GetNextFireTimeUtc() == null)
                            {
                                qs.NotifySchedulerListenersFinalized(jec.Trigger);
                            }
                            Complete(true);
                        }
                        catch (SchedulerException se)
                        {
                            qs.NotifySchedulerListenersError(
                                string.Format(CultureInfo.InvariantCulture, "Error during veto of Job ({0}: couldn't finalize execution.",
                                              jec.JobDetail.Key), se);
                        }
                        break;
                    }

                    DateTimeOffset startTime = SystemTime.UtcNow();
                    DateTimeOffset endTime;

                    // Execute the job
                    try
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("Calling Execute on job " + jobDetail.Key);
                        }
                        job.Execute(jec);
                        endTime = SystemTime.UtcNow();
                    }
                    catch (JobExecutionException jee)
                    {
                        endTime = SystemTime.UtcNow();
                        jobExEx = jee;
                        log.Info(string.Format(CultureInfo.InvariantCulture, "Job {0} threw a JobExecutionException: ", jobDetail.Key), jobExEx);
                    }
                    catch (Exception e)
                    {
                        endTime = SystemTime.UtcNow();
                        log.Error(string.Format(CultureInfo.InvariantCulture, "Job {0} threw an unhandled Exception: ", jobDetail.Key), e);
                        SchedulerException se = new SchedulerException("Job threw an unhandled exception.", e);
                        qs.NotifySchedulerListenersError(
                            string.Format(CultureInfo.InvariantCulture, "Job ({0} threw an exception.", jec.JobDetail.Key), se);
                        jobExEx = new JobExecutionException(se, false);
                    }

                    jec.JobRunTime = endTime - startTime;

                    // notify all job listeners
                    if (!NotifyJobListenersComplete(jec, jobExEx))
                    {
                        break;
                    }

                    instCode = SchedulerInstruction.NoInstruction;

                    // update the trigger
                    try
                    {
                        instCode = trigger.ExecutionComplete(jec, jobExEx);
                        if (log.IsDebugEnabled)
                        {
                            log.Debug(string.Format(CultureInfo.InvariantCulture, "Trigger instruction : {0}", instCode));
                        }
                    }
                    catch (Exception e)
                    {
                        // If this happens, there's a bug in the trigger...
                        SchedulerException se = new SchedulerException("Trigger threw an unhandled exception.", e);
                        qs.NotifySchedulerListenersError("Please report this error to the Quartz developers.", se);
                    }

                    // notify all trigger listeners
                    if (!NotifyTriggerListenersComplete(jec, instCode))
                    {
                        break;
                    }
                    // update job/trigger or re-Execute job
                    if (instCode == SchedulerInstruction.ReExecuteJob)
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("Rescheduling trigger to reexecute");
                        }
                        jec.IncrementRefireCount();
                        try
                        {
                            Complete(false);
                        }
                        catch (SchedulerException se)
                        {
                            qs.NotifySchedulerListenersError(
                                string.Format(CultureInfo.InvariantCulture, "Error executing Job ({0}: couldn't finalize execution.",
                                              jec.JobDetail.Key), se);
                        }
                        continue;
                    }

                    try
                    {
                        Complete(true);
                    }
                    catch (SchedulerException se)
                    {
                        qs.NotifySchedulerListenersError(
                            string.Format(CultureInfo.InvariantCulture, "Error executing Job ({0}: couldn't finalize execution.",
                                          jec.JobDetail.Key), se);
                        continue;
                    }

                    try
                    {
                        qs.NotifyJobStoreJobComplete(trigger, jobDetail, instCode);
                    }
                    catch (JobPersistenceException jpe)
                    {
                        qs.NotifySchedulerListenersError(
                            string.Format(CultureInfo.InvariantCulture, "An error occured while marking executed job complete. job= '{0}'",
                                          jobDetail.Key), jpe);
                        if (!CompleteTriggerRetryLoop(trigger, jobDetail, instCode))
                        {
                            return;
                        }
                    }

                    break;
                } while (true);

            }
            finally
            {
                qs.RemoveInternalSchedulerListener(this);
            }
        }
Exemple #57
0
 public virtual void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
 {
     lock (executingJobs)
     {
         executingJobs.Remove(((IOperableTrigger) context.Trigger).FireInstanceId);
     }
 }
        /// <summary>
        /// Called by the <see cref="IScheduler" /> after a <see cref="IJobDetail" />
        /// has been executed, and be for the associated <see cref="ITrigger" />'s
        /// <see cref="IOperableTrigger.Triggered" /> method has been called.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="jobException"></param>
        public virtual Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            ITrigger trigger = context.Trigger;

            object[] args;

            if (jobException != null)
            {
                if (!Log.IsWarnEnabled())
                {
                    return TaskUtil.CompletedTask;
                }

                string errMsg = jobException.Message;
                args =
                    new object[]
                    {
                        context.JobDetail.Key.Name, context.JobDetail.Key.Group, SystemTime.UtcNow(), trigger.Key.Name, trigger.Key.Group,
                        trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), context.RefireCount, errMsg
                    };

                Log.WarnException(string.Format(CultureInfo.InvariantCulture, JobFailedMessage, args), jobException);
            }
            else
            {
                if (!Log.IsInfoEnabled())
                {
                    return TaskUtil.CompletedTask;
                }

                string result = Convert.ToString(context.Result, CultureInfo.InvariantCulture);
                args =
                    new object[]
                    {
                        context.JobDetail.Key.Name, context.JobDetail.Key.Group, SystemTime.UtcNow(), trigger.Key.Name, trigger.Key.Group,
                        trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), context.RefireCount, result
                    };

                Log.Info(string.Format(CultureInfo.InvariantCulture, JobSuccessMessage, args));
            }
            return TaskUtil.CompletedTask;
        }
Exemple #59
0
        /// <summary>
        /// Notifies the job listeners that job was executed.
        /// </summary>
        /// <param name="jec">The jec.</param>
        /// <param name="je">The je.</param>
        public virtual void NotifyJobListenersWasExecuted(IJobExecutionContext jec, JobExecutionException je)
        {
            // build a list of all job listeners that are to be notified...
            IEnumerable<IJobListener> listeners = BuildJobListenerList();

            // notify all job listeners
            foreach (IJobListener jl in listeners)
            {
                if (!MatchJobListener(jl, jec.JobDetail.Key))
                {
                    continue;
                }
                try
                {
                    jl.JobWasExecuted(jec, je);
                }
                catch (Exception e)
                {
                    SchedulerException se = new SchedulerException(string.Format(CultureInfo.InvariantCulture, "JobListener '{0}' threw exception: {1}", jl.Name, e.Message), e);
                    throw se;
                }
            }
        }
Exemple #60
0
		private bool NotifyJobListenersComplete(JobExecutionContext ctx, JobExecutionException jobExEx)
		{
			try
			{
				qs.NotifyJobListenersWasExecuted(ctx, jobExEx);
			}
			catch (SchedulerException se)
			{
				qs.NotifySchedulerListenersError(
					string.Format(CultureInfo.InvariantCulture, "Unable to notify JobListener(s) of Job that was executed: (error will be ignored). trigger= {0} job= {1}", ctx.Trigger.FullName, ctx.JobDetail.FullName), se);

				return false;
			}

			return true;
		}