Skip to content
This repository has been archived by the owner on Jun 21, 2018. It is now read-only.

Commit

Permalink
Fix #21
Browse files Browse the repository at this point in the history
  • Loading branch information
gmlexx committed May 18, 2016
1 parent 85e58e2 commit 18e481b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
11 changes: 10 additions & 1 deletion moira/api/resources/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions moira/api/resources/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion moira/checker/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=']})
Expand Down

0 comments on commit 18e481b

Please sign in to comment.