From 18e481bc20f1c2d3f44e0226d05a954f91fa22df Mon Sep 17 00:00:00 2001 From: Alexey Larkov Date: Wed, 18 May 2016 22:06:14 +0300 Subject: [PATCH] Fix #21 --- moira/api/resources/redis.py | 11 ++++++++++- moira/api/resources/trigger.py | 1 + moira/checker/trigger.py | 4 +++- tests/functional/test_api.py | 4 ++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/moira/api/resources/redis.py b/moira/api/resources/redis.py index 2cc7a69..358b600 100644 --- a/moira/api/resources/redis.py +++ b/moira/api/resources/redis.py @@ -3,6 +3,7 @@ from twisted.web.resource import Resource from moira.api.request import check_trigger, check_json +from moira.checker import state class RedisResouce(Resource): @@ -33,7 +34,15 @@ def save_trigger(self, request, trigger_id, message): if last_check: last_check['metrics'] = {} - yield self.db.setTriggerLastCheck(trigger_id, last_check) + else: + last_check = { + "metrics": {}, + "state": state.NODATA, + "score": 0 + } + print last_check + + yield self.db.setTriggerLastCheck(trigger_id, last_check) yield self.db.delTriggerCheckLock(trigger_id) diff --git a/moira/api/resources/trigger.py b/moira/api/resources/trigger.py index e4bcfad..056edeb 100644 --- a/moira/api/resources/trigger.py +++ b/moira/api/resources/trigger.py @@ -115,6 +115,7 @@ def render_PUT(self, request): trigger_id = str(uuid.uuid4()) yield self.save_trigger(request, trigger_id, "trigger created") + class Page(RedisResouce): def __init__(self, db): diff --git a/moira/checker/trigger.py b/moira/checker/trigger.py index a6def53..aa55122 100644 --- a/moira/checker/trigger.py +++ b/moira/checker/trigger.py @@ -30,13 +30,15 @@ def init(self, now, fromTime=None): self.ttl = self.struct.get("ttl") self.ttl_state = self.struct.get("ttl_state", state.NODATA) self.last_check = yield self.db.getTriggerLastCheck(self.id) + begin = (fromTime or now) - 3600 if self.last_check is None: - begin = (fromTime or now) - 3600 self.last_check = { "metrics": {}, "state": state.NODATA, "timestamp": begin } + if self.last_check.get("timestamp") is None: + self.last_check["timestamp"] = begin if self.last_check.get("score") is None: self.update_score = True defer.returnValue(True) diff --git a/tests/functional/test_api.py b/tests/functional/test_api.py index 54d99cc..0a26cd5 100644 --- a/tests/functional/test_api.py +++ b/tests/functional/test_api.py @@ -126,8 +126,8 @@ def testTriggersPaging(self): response, triggers = yield self.request('GET', 'trigger/page?p=0&size=10', add_headers={'Cookie': ['moira_filter_tags=tag1; moira_filter_ok=true']}) - self.assertEqual(1, len(triggers["list"])) - self.assertEqual(1, triggers["total"]) + self.assertEqual(0, len(triggers["list"])) + self.assertEqual(0, triggers["total"]) response, triggers = yield self.request('GET', 'trigger/page?p=0&size=10', add_headers={'Cookie': ['moira_filter_tags=']})