From 69381f1c618a10ebe7155fb33acf6474d61f8dbd Mon Sep 17 00:00:00 2001 From: vapao Date: Mon, 4 May 2020 18:58:05 +0800 Subject: [PATCH] =?UTF-8?q?F=20=E4=BF=AE=E5=A4=8D=E6=95=85=E9=9A=9C?= =?UTF-8?q?=E6=81=A2=E5=A4=8D=E5=91=8A=E8=AD=A6=E5=8F=AF=E8=83=BD=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=8F=91=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/monitor/scheduler.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spug_api/apps/monitor/scheduler.py b/spug_api/apps/monitor/scheduler.py index f5e9edb..21253f7 100644 --- a/spug_api/apps/monitor/scheduler.py +++ b/spug_api/apps/monitor/scheduler.py @@ -54,9 +54,9 @@ class Scheduler: elif mode == '4': spug.notify_by_email(event, obj) - def _handle_notify(self, obj, old_status, out): + def _handle_notify(self, obj, is_notified, out): if obj.latest_status == 0: - if old_status == 1: + if is_notified: self._record_alarm(obj, '2') logger.info(f'{human_datetime()} recover job_id: {obj.id}') self._do_notify('2', obj, out) @@ -84,18 +84,18 @@ class Scheduler: elif event.code == EVENT_JOB_EXECUTED: is_ok, out = event.retval obj = Detection.objects.filter(pk=event.job_id).first() - old_status = obj.latest_status - obj.latest_status = 0 if is_ok else 1 - obj.latest_run_time = human_datetime(event.scheduled_run_time) - if old_status in [0, None] and is_ok is False: + is_notified = True if obj.latest_notify_time else False + if obj.latest_status in [0, None] and is_ok is False: obj.latest_fault_time = int(time.time()) - if obj.latest_status == 0: + if is_ok: obj.latest_notify_time = 0 obj.fault_times = 0 else: obj.fault_times += 1 + obj.latest_status = 0 if is_ok else 1 + obj.latest_run_time = human_datetime(event.scheduled_run_time) obj.save() - self._handle_notify(obj, old_status, out) + self._handle_notify(obj, is_notified, out) def _init(self): self.scheduler.start()