Commit 3ca7bdd1 authored by Hiro's avatar Hiro 🏄
Browse files

Fix error and call backs in email message responder

parent e91d4b2a
......@@ -151,21 +151,21 @@ class EmailParser(object):
return request
def check_num_requests(self, request_id, hid, request_service, limit):
def too_many_requests(self, request_id, hid, request_service, limit):
# check limit first
num_requests = limit
if hid.hexdigest() == self.settings.get('test_hid'):
num_requests = 1
num_requests = 0
else:
num_requests = yield conn.get_num_requests(
id=hid.hexdigest(), service=request_service
)
if num_requests[0][0] < email_requests_limit:
return 1
else:
return 0
else:
return 1
def parse(self, msg_str):
......@@ -240,7 +240,14 @@ class EmailParser(object):
"Found request for {}.".format(request['command']),
system="email parser"
)
if self.check_num_requests(request['id'], hid, request['service'], email_requests_limit):
check = yield self.too_many_requests(request['id'], hid, request['service'], email_requests_limit):
if check
log.msg(
"Discarded. Too many requests from {}.".format(
hid.hexdigest()
), system="email parser"
)
else:
conn.new_request(
id=request['id'],
command=request['command'],
......@@ -250,13 +257,6 @@ class EmailParser(object):
date=now_str,
status="ONHOLD",
)
else:
log.msg(
"Discarded. Too many requests from {}.".format(
hid.hexdigest()
), system="email parser"
)
else:
log.msg(
"Request not found",
......
......@@ -124,7 +124,14 @@ class TwitterParser(object):
id=str(request['id']), service=request['service']
)
if num_requests[0][0] < twitter_requests_limit:
if num_requests[0][0] > twitter_requests_limit:
log.msg(
"Discarded. Too many requests from {}.".format(
hid.hexdigest()
), system="twitter parser"
)
else:
conn.new_request(
id=str(request['id']),
command=request['command'],
......@@ -135,13 +142,6 @@ class TwitterParser(object):
status="ONHOLD",
)
else:
log.msg(
"Discarded. Too many requests from {}.".format(
hid.hexdigest()
), system="twitter parser"
)
def parse_errback(self, error):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment