Rfaulk has submitted this change and it was merged. Change subject: revert. last change, meant to be in separate branch. ......................................................................
revert. last change, meant to be in separate branch. Change-Id: I6cdd91bba712941f3efc024eac482468c1c0ac80 --- M user_metrics/api/run.py D user_metrics/api/run_handlers.py 2 files changed, 60 insertions(+), 59 deletions(-) Approvals: Rfaulk: Verified; Looks good to me, approved diff --git a/user_metrics/api/run.py b/user_metrics/api/run.py index 7cea991..4548038 100644 --- a/user_metrics/api/run.py +++ b/user_metrics/api/run.py @@ -46,13 +46,66 @@ 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 @@ -88,7 +141,10 @@ if __name__ == '__main__': - app.run(debug=True, - use_reloader=False, - host=settings.__instance_host__, - port=settings.__instance_port__,) + try: + app.run(debug=True, + use_reloader=False, + host=settings.__instance_host__, + port=settings.__instance_port__,) + finally: + teardown() diff --git a/user_metrics/api/run_handlers.py b/user_metrics/api/run_handlers.py deleted file mode 100644 index 8ebcd47..0000000 --- a/user_metrics/api/run_handlers.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/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/72478 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6cdd91bba712941f3efc024eac482468c1c0ac80 Gerrit-PatchSet: 1 Gerrit-Project: analytics/user-metrics Gerrit-Branch: master Gerrit-Owner: Rfaulk <[email protected]> Gerrit-Reviewer: Rfaulk <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
