Rfaulk has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/72476


Change subject: mod/add. move handlers outside of apache context.
......................................................................

mod/add. move handlers outside of apache context.

Change-Id: I0b6ab2b5f0394b36a9b756fa20441609ab18550c
---
M user_metrics/api/run.py
A user_metrics/api/run_handlers.py
2 files changed, 59 insertions(+), 60 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/analytics/user-metrics 
refs/changes/76/72476/1

diff --git a/user_metrics/api/run.py b/user_metrics/api/run.py
index 4548038..7cea991 100644
--- a/user_metrics/api/run.py
+++ b/user_metrics/api/run.py
@@ -46,66 +46,13 @@
 import multiprocessing as mp
 
 from user_metrics.config import logging, settings
-from user_metrics.api.engine.request_manager import job_control, \
-    requests_notification_callback
-from user_metrics.api.engine.response_handler import process_responses
 from user_metrics.api.views import app
-from user_metrics.api.engine.request_manager import api_request_queue, \
-    req_notification_queue_out, req_notification_queue_in, api_response_queue
-from user_metrics.utils import terminate_process_with_checks
-
-job_controller_proc = None
-response_controller_proc = None
-rm_callback_proc = None
-
-
-######
-#
-# Define Custom Classes
-#
-#######
-
-
-def teardown():
-    """ When the instance is deleted store the pickled data and shutdown
-        the job controller """
-
-    # Try to shutdown the job control proc gracefully
-    try:
-        terminate_process_with_checks(job_controller_proc)
-        terminate_process_with_checks(response_controller_proc)
-        terminate_process_with_checks(rm_callback_proc)
-
-    except Exception:
-        logging.error(__name__ + ' :: Could not shut down callbacks.')
-
-
-def setup_controller(req_queue, res_queue, msg_queue_in, msg_queue_out):
-    """
-        Sets up the process that handles API jobs
-    """
-    job_controller_proc = mp.Process(target=job_control,
-                                     args=(req_queue, res_queue))
-    response_controller_proc = mp.Process(target=process_responses,
-                                          args=(res_queue,
-                                                msg_queue_in))
-    rm_callback_proc = mp.Process(target=requests_notification_callback,
-                                  args=(msg_queue_in,
-                                        msg_queue_out))
-    job_controller_proc.start()
-    response_controller_proc.start()
-    rm_callback_proc.start()
 
 ######
 #
 # Execution
 #
 #######
-
-# initialize API data - get the instance
-
-setup_controller(api_request_queue, api_response_queue,
-                 req_notification_queue_in, req_notification_queue_out)
 
 app.config['SECRET_KEY'] = settings.__secret_key__
 app.config['VERSION'] = settings.version
@@ -141,10 +88,7 @@
 
 
 if __name__ == '__main__':
-    try:
-        app.run(debug=True,
-                use_reloader=False,
-                host=settings.__instance_host__,
-                port=settings.__instance_port__,)
-    finally:
-        teardown()
+    app.run(debug=True,
+            use_reloader=False,
+            host=settings.__instance_host__,
+            port=settings.__instance_port__,)
diff --git a/user_metrics/api/run_handlers.py b/user_metrics/api/run_handlers.py
new file mode 100644
index 0000000..8ebcd47
--- /dev/null
+++ b/user_metrics/api/run_handlers.py
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+"""
+This module handle the exescution of the job handler components of the User
+metrics API.  This piece consists of three components:
+
+    Job Controller:
+        Schedules incoming requests for execution.
+
+    Response Handler:
+        Synthesizes responses from completed jobs.
+
+    Request Notification Callback:
+        Handles sending notifications on job status.
+"""
+
+from user_metrics.api.engine.response_handler import process_responses
+from user_metrics.api.engine.request_manager import api_request_queue, \
+    req_notification_queue_out, req_notification_queue_in, api_response_queue
+from user_metrics.api.engine.request_manager import job_control, \
+    requests_notification_callback
+from user_metrics.api.engine.response_handler import process_responses
+from user_metrics.utils import terminate_process_with_checks
+
+def setup_controller(req_queue, res_queue, msg_queue_in, msg_queue_out):
+    """
+        Sets up the process that handles API jobs
+    """
+    job_controller_proc = mp.Process(target=job_control,
+                                     args=(req_queue, res_queue))
+    response_controller_proc = mp.Process(target=process_responses,
+                                          args=(res_queue,
+                                                msg_queue_in))
+    rm_callback_proc = mp.Process(target=requests_notification_callback,
+                                  args=(msg_queue_in,
+                                        msg_queue_out))
+    job_controller_proc.start()
+    response_controller_proc.start()
+    rm_callback_proc.start()
+
+
+def teardown():
+    """ When the instance is deleted store the pickled data and shutdown
+        the job controller """
+
+    # Try to shutdown the job control proc gracefully
+    try:
+        terminate_process_with_checks(job_controller_proc)
+        terminate_process_with_checks(response_controller_proc)
+        terminate_process_with_checks(rm_callback_proc)
+
+    except Exception:
+        logging.error(__name__ + ' :: Could not shut down callbacks.')
+

-- 
To view, visit https://gerrit.wikimedia.org/r/72476
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0b6ab2b5f0394b36a9b756fa20441609ab18550c
Gerrit-PatchSet: 1
Gerrit-Project: analytics/user-metrics
Gerrit-Branch: master
Gerrit-Owner: Rfaulk <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to