private void DoTask() { try { _batchConfig.SetSchedulerTime(DateTime.Now); _batch.SetBatchConfig(_batchConfig); _batch.Prepare(); while (_isRunning) { if (!_batch.IsRun()) { return; } Log.Info($"{_batchConfig.BatchName}当前执行{_batchConfig.SchedulerTime}"); _batch.Execute(); _batch.Clear(); Log.Info($"{_batchConfig.BatchName}执行完成{_batchConfig.SchedulerTime}"); _batch.UpdateTimeStamp(_timeSpan); Thread.Sleep(_timeSpan); } } catch (Exception ex) { EmailErr(new AggregateException("执行错误", ex)); } }
/// <summary> /// 调度框架使用 /// </summary> /// <param name="batch"></param> /// <param name="config"></param> public static void RunBatch(IBatch batch, BatchConfig config) { batch.SetBatchConfig(config); if (!batch.IsRun()) { return; } batch.Prepare(); batch.Execute(); batch.Clear(); }