Commit 1b67ec28 authored by Hiro's avatar Hiro 🏄
Browse files

Merge branch 'master' into twitter

parents 79902849 93c972af
......@@ -198,6 +198,23 @@ class EmailParser(object):
return request
def check_num_requests(self, request_id, request_service, limit):
now_str = datetime.now().strftime("%Y%m%d%H%M%S")
dbname = self.settings.get("dbname")
conn = SQLite3(dbname)
hid = hashlib.sha256(request['id'].encode('utf-8'))
# check limits first
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
@defer.inlineCallbacks
def parse_callback(self, request):
"""
......@@ -212,30 +229,13 @@ class EmailParser(object):
execution details.
"""
email_requests_limit = self.settings.get("email_requests_limit")
log.msg(
"Found request for {}.".format(request['command']),
system="email parser"
)
if request["command"]:
now_str = datetime.now().strftime("%Y%m%d%H%M%S")
dbname = self.settings.get("dbname")
conn = SQLite3(dbname)
hid = hashlib.sha256(request['id'].encode('utf-8'))
# check limits first
num_requests = yield conn.get_num_requests(
id=hid.hexdigest(), service=request['service']
)
if num_requests[0][0] > email_requests_limit:
log.msg(
"Discarded. Too many requests from {}.".format(
hid.hexdigest
), system="email parser"
log.msg(
"Found request for {}.".format(request['command']),
system="email parser"
)
else:
if check_num_requests(request['id'], request['service'], email_requests_limit):
conn.new_request(
id=request['id'],
command=request['command'],
......@@ -245,6 +245,18 @@ 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",
system="email parser"
)
def parse_errback(self, error):
"""
......
......@@ -100,14 +100,18 @@ if __name__ == "__main__":
else:
password = "yourPassword"
status_file = open(STATUS_FILE,'w')
status_file = open(STATUS_FILE, 'r')
message = status_file.read()
status_file.close()
try:
status, message = send_email_from_gmail(password)
except Exception as e:
status = UNKNOWN
message = repr(e)
status_file.write("UNKNOWN: %s" % message)
status_file = open(STATUS_FILE,'w')
status_file.write("UNKNOWN\n3: %s" % message)
status_file.close()
time.sleep(600)
......@@ -119,6 +123,7 @@ if __name__ == "__main__":
status = CRITICAL
message = repr(e)
finally:
status_file = open(STATUS_FILE,'w')
if status == OK:
status_file.write("OK\n0: %s" % message)
elif status == WARNING:
......@@ -129,4 +134,6 @@ if __name__ == "__main__":
status_file.write("UNKNOWN\n3: %s" % message)
status = UNKNOWN
status_file.close()
sys.exit(status)
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