summaryrefslogtreecommitdiff
path: root/service/app
diff options
context:
space:
mode:
authorBruno Wagner Goncalves and Patrick Maia <pixelated-team+bwagner+pmaia@thoughtworks.com>2014-08-14 14:55:22 -0300
committerPatrick Maia <patrickjourdanmaia@gmail.com>2014-08-14 14:55:22 -0300
commitd18d9c64168737993821347b5a99a0dd6f061534 (patch)
treebe77ddeda6e68f4e8523e05d311a0fd5f4645bb9 /service/app
parenta864a01a9883db7eb2f84e616a5f294ec2193bfb (diff)
moves reactor logic to its own module and removed some unused code
Diffstat (limited to 'service/app')
-rw-r--r--service/app/pixelated_user_agent.py38
-rw-r--r--service/app/reactor_manager.py26
2 files changed, 32 insertions, 32 deletions
diff --git a/service/app/pixelated_user_agent.py b/service/app/pixelated_user_agent.py
index 739cb57f..e927efd5 100644
--- a/service/app/pixelated_user_agent.py
+++ b/service/app/pixelated_user_agent.py
@@ -2,7 +2,11 @@ import json
import datetime
import dateutil.parser as dateparser
-from flask import Flask, request, Response
+from flask import Flask
+from flask import request
+from flask import Response
+
+import app.reactor_manager as reactor_manager
import app.search_query as search_query
from app.adapter.mail_service import MailService
from app.adapter.mail_converter import MailConverter
@@ -16,10 +20,6 @@ converter = MailConverter(mail_service)
account = None
-def from_iso8061_to_date(iso8061):
- return datetime.datetime.strptime(iso8061, "%Y-%m-%dT%H:%M:%S%z")
-
-
def respond_json(entity):
response = json.dumps(entity)
return Response(response=response, mimetype="application/json")
@@ -133,37 +133,11 @@ def index():
def setup():
- start_reactor()
+ reactor_manager.start_reactor()
app.config.from_envvar('PIXELATED_UA_CFG')
account = app.config['ACCOUNT']
app.run(host=app.config['HOST'], debug=app.config['DEBUG'], port=app.config['PORT'])
-from threading import Thread
-from twisted.internet import reactor
-
-import signal
-import sys
-
-
-def signal_handler(signal, frame):
- stop_reactor_on_exit()
- sys.exit(0)
-signal.signal(signal.SIGINT, signal_handler)
-
-
-def start_reactor():
- def start_reactor_run():
- reactor.run(False)
-
- global REACTOR_THREAD
- REACTOR_THREAD = Thread(target=start_reactor_run)
- REACTOR_THREAD.start()
-
-
-def stop_reactor_on_exit():
- reactor.callFromThread(reactor.stop)
- global REACTOR_THREAD
- REACTOR_THREAD = None
if __name__ == '__main__':
setup()
diff --git a/service/app/reactor_manager.py b/service/app/reactor_manager.py
new file mode 100644
index 00000000..01f7f545
--- /dev/null
+++ b/service/app/reactor_manager.py
@@ -0,0 +1,26 @@
+import signal
+import sys
+from threading import Thread
+from twisted.internet import reactor
+
+
+def signal_handler(signal, frame):
+ stop_reactor_on_exit()
+ sys.exit(0)
+
+
+def start_reactor():
+ def start_reactor_run():
+ reactor.run(False)
+
+ global REACTOR_THREAD
+ REACTOR_THREAD = Thread(target=start_reactor_run)
+ REACTOR_THREAD.start()
+
+
+def stop_reactor_on_exit():
+ reactor.callFromThread(reactor.stop)
+ global REACTOR_THREAD
+ REACTOR_THREAD = None
+
+signal.signal(signal.SIGINT, signal_handler)