WaitingResumption ISchedulerService.Get(long id) { return _resumptionRepository.FindBy(id); }
public void Run() { this._running = true; if (this._timer == null) { this._timer = new System.Timers.Timer(this._interval); this._timer.Elapsed += (state, args) => { if (!this._running) { return; } //HACK:一个调度实例同时只有一个worker线程激活 if (this._charging) { return; } lock (this._lock) { if (this._charging) { return; } this._charging = true; } //this._log.Debug("ChargeResumption"); try { this.ChargeResumption() //.AsParallel()//TODO:parallel调度效果需要进一步验证 //.ForAll(r => //TODO:调整为按流程串行调度,避免意外并发问题和保证调度顺序 .ForEach(r => { if (!this._running) { return; } try { //HACK:由于匿名委托共享Run的callcontext因此需要单独声明session using (var session = Taobao.Infrastructure.Castles.NHibernateRepositoryUtility.UnmanagedSession()) { this.Resume(r); session.Flush(); } //尝试将流程置为active using (var session = Taobao.Infrastructure.Castles.NHibernateRepositoryUtility.UnmanagedSession()) { var processService = DependencyResolver.Resolve <IProcessService>(); var resumption = _repository.FindBy(r); //if (resumption.Process.Status == ProcessStatus.Running) //{ if (resumption is SubProcessCreateResumption || resumption is WorkItemCreateResumption) { processService.TrySetAsActiveAtResumption(resumption.Process, resumption); session.Flush(); } //} } } catch (Exception e) { //HACK:此处异常将被认为是意外出现的异常? this._log.Error(string.Format("Resumption Error Occur At #{0}", r), e); } }); } catch (Exception e) { this._log.Fatal("Charging error", e); } finally { this._charging = false; } }; this._timer.Start(); } this._log.Info("NTFE-BPM应用调度器启动"); }