private void RunServiceJob(IServiceJob job, TimeSpan timeout) { job.ShouldNotBeNull("job"); if (IsDebugEnabled) { log.Debug(@"서비스 작업[{0}]을 실행합니다...", job.Name); } try { _scheduler = _factory.GetScheduler(); _scheduler.Start(); _scheduler.ScheduleServiceJob(job); Thread.Sleep(timeout); } finally { _scheduler.Shutdown(true); if (IsDebugEnabled) { log.Debug(@"서비스 작업[{0}] 실행을 완료했습니다.", job.Name); } } }
/// <summary> /// Schedules the next execution of the specified job /// </summary> /// <param name="job">The job.</param> internal void ScheduleNextExecution(IServiceJob job) { this._log.Debug(string.Format("SchedulingService.ScheduleNextExecution({0})", job.Name)); var currentTime = SystemTime.Now; var nextTime = job.NextOccurence(currentTime); PersistentTimer timer = new PersistentTimer((nextTime - currentTime).TotalMilliseconds, job.Name); timer.AutoReset = false; timer.Enabled = true; timer.Elapsed += (source, e) => { timer.Stop(); if (!job.IsExecuting && this.IsRunning) { job.Execute(); } this.ScheduleNextExecution(job); }; this._timers.Add(timer); if (this._jobs[job] != null) { this._jobs[job].Stop(); this._jobs[job].Dispose(); } this._jobs[job] = timer; // overwrite the timer. }
/// <summary> /// 초기 상태 정보를 설정합니다. /// </summary> /// <param name="serviceJob"></param> private static void BuildJobDataMap(IServiceJob serviceJob) { if (serviceJob != null && serviceJob is JobDetail) { ((JobDetail)serviceJob).SetJobData(serviceJob.StateMap); } }
/// <summary> /// Job 상태정보를 담은 <see cref="JobDataMap"/>에서 해당 키의 값을 반환합니다. 없으면, null을 반환합니다. /// </summary> public static object GetJobData(this IServiceJob serviceJob, object key) { serviceJob.ShouldNotBeNull("serviceJob"); if (serviceJob is JobDetail) { return(((JobDetail)serviceJob).GetJobData(key)); } return(null); }
/// <summary> /// 지정된 Component Id를 가진 <see cref="IServiceJob"/> 컴포넌트를 Resolve합니다. /// </summary> /// <param name="componentId"></param> /// <param name="serviceJob"></param> /// <returns></returns> public static bool TryResolveJob(string componentId, out IServiceJob serviceJob) { serviceJob = With.TryFunction<IServiceJob>(() => ResolveJob(componentId), null, ex => { if(log.IsErrorEnabled) { log.Error("ServiceJob Component [{0}] 를 Resolve하는데 예외가 발생했습니다!!!", componentId); log.Error(ex); } }); return (serviceJob != null); }
/// <summary> /// 지정된 Component Id를 가진 <see cref="IServiceJob"/> 컴포넌트를 Resolve합니다. /// </summary> /// <param name="componentId"></param> /// <param name="serviceJob"></param> /// <returns></returns> public static bool TryResolveJob(string componentId, out IServiceJob serviceJob) { serviceJob = With.TryFunction <IServiceJob>(() => ResolveJob(componentId), null, ex => { if (log.IsErrorEnabled) { log.Error("ServiceJob Component [{0}] 를 Resolve하는데 예외가 발생했습니다!!!", componentId); log.Error(ex); } }); return(serviceJob != null); }
private void RunServiceJob(IServiceJob job, TimeSpan timeout) { job.ShouldNotBeNull("job"); if(IsDebugEnabled) log.Debug(@"서비스 작업[{0}]을 실행합니다...", job.Name); try { _scheduler = _factory.GetScheduler(); _scheduler.Start(); _scheduler.ScheduleServiceJob(job); Thread.Sleep(timeout); } finally { _scheduler.Shutdown(true); if(IsDebugEnabled) log.Debug(@"서비스 작업[{0}] 실행을 완료했습니다.", job.Name); } }
private void RunBasicJob(IServiceJob job) { try { var scope = DIContainer.Current.BeginLifetimeScope(); var jobObject = scope.Container.Resolve(job.JobClassType); job.InvokeMethodInfo.Invoke(jobObject, job.IsParameterlessMethod ? null : new object[] { ServiceName }); _basicJobsInWork.Add(jobObject, scope); } catch (Exception e) { if (OnException != null) { OnException(new ServiceExceptionArgs(ServiceName, e)); } else { throw; } } }
/// <summary> /// Returns a boolean indicating whether the name matches the job /// </summary> /// <param name="job">The job.</param> /// <param name="name">The name to compare to.</param> /// <returns></returns> private static bool JobComparison(IServiceJob job, string name) { return(job.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)); }
/// <summary> /// 초기 상태 정보를 설정합니다. /// </summary> /// <param name="serviceJob"></param> private static void BuildJobDataMap(IServiceJob serviceJob) { if(serviceJob != null && serviceJob is JobDetail) { ((JobDetail)serviceJob).SetJobData(serviceJob.StateMap); } }