1. HandleService: 从Redis中获取异常信息, 入库并发送通知到相关责任人。
2. HealthyCheckService: 对站点指定页面进行模拟访问, 如果请求成功或者返回的内容是约定的内容就表示正常, 否则就会产生一个异常信息, 并发送到http服务端。
HandleService 的处理流程包括1. 从Redis中获取数据 2. 信息持久化到数据库 3. 更新DB中的状态 4 删除Redis中的数据
public void Handle() { ThreadPool.SetMaxThreads(10, 40); //设置线程 while (true) { string errorEntityId = RedisHelper.DequeueItemFromList("ErrorEntityQueue"); //从Redis中获取数据 if (!string.IsNullOrEmpty(errorEntityId)) { ThreadPool.QueueUserWorkItem(state => { try { //0. 从Redis中获取数据 var errorEntityDto = RedisHelper.Get<ErrorEntityDto>(errorEntityId); //1. 信息持久到DB, 方便后续查看,统计 ErrorEntity errorEntity = null; errorEntity = Mapper.Map<ErrorEntity>(errorEntityDto); errorEntity.NotifyStatus = 0; //未通知 _errorEntityBusiness.Insert(errorEntity, false); //2. 通知到相关责任人 bool issuccess = Notity(errorEntityDto); if (issuccess) { //3. 更新DB中的状态 _errorEntityBusiness.UpdateBySql(string.Format("set NotifyStatus = 1 where Id='{0}'", errorEntity.Id)); } //4. 删除redis中的数据 RedisHelper.Del(errorEntityId); } catch (Exception exception) { LogHelper.Error("处理发生异常", exception); } //todo 这里应该以有个补救措施, 如果通知失败。 应该再另外一个job中对这些失败的通知重新发送。这里就不写了 }, errorEntityId); } else { Thread.Sleep(5000); //如果没有取到数据,则暂停5s } } }