def queue_monitor(self): counter = 0 while True: time.sleep((counter or 1)**3 * 10) qsize = self._executor._work_queue.qsize() if qsize > 0: if counter > 0: content = '请检查监控、任务计划或批量执行等避免长耗时任务,必要时可重启服务清空队列。' try: Notify.make_system_notify(f'执行队列堆积({qsize})', content) except Exception as e: logging.warning(e) finally: connections.close_all() logging.warning(f'!!! 执行队列堆积({qsize})') counter += 1 else: counter = 0
def handle_request(url, data, mode=None): try: res = requests.post(url, json=data, timeout=30) except Exception as e: return Notify.make_system_notify('通知发送失败', f'接口调用异常: {e}') if res.status_code != 200: return Notify.make_system_notify('通知发送失败', f'返回状态码:{res.status_code}, 请求URL:{res.url}') if mode in ['dd', 'wx']: res = res.json() if res.get('errcode') == 0: return elif mode == 'spug': res = res.json() if not res.get('error'): return elif mode == 'fs': res = res.json() if res.get('StatusCode') == 0: return else: raise NotImplementedError Notify.make_system_notify('通知发送失败', f'返回数据:{res}')