Repository: incubator-airflow Updated Branches: refs/heads/master ac397cf71 -> 79e7c9071
[AIRFLOW-2204] Fix webserver debug mode The command `airflow webserver -d` crashes because it tries to call the method run from the cached_app returned value, i.e. a DispatcherMiddleware instance. To run the flask app in debug mode (without gunicorn) it has to be created directly via create_app, that returns a Flask instance. Ref: https://issues.apache.org/jira/browse/AIRFLOW-2204 Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/022b7ae3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/022b7ae3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/022b7ae3 Branch: refs/heads/master Commit: 022b7ae3f3c6492f1188c5bcd28a65fc0222ee5a Parents: 76d11f2 Author: bbonagura9 <[email protected]> Authored: Fri Mar 9 21:30:04 2018 -0300 Committer: bbonagura9 <[email protected]> Committed: Sat Mar 10 17:58:33 2018 -0300 ---------------------------------------------------------------------- airflow/bin/cli.py | 10 ++++++---- tests/cli/test_cli.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/022b7ae3/airflow/bin/cli.py ---------------------------------------------------------------------- diff --git a/airflow/bin/cli.py b/airflow/bin/cli.py index 98b4321..449d8ca 100755 --- a/airflow/bin/cli.py +++ b/airflow/bin/cli.py @@ -56,8 +56,8 @@ from airflow.ti_deps.dep_context import (DepContext, SCHEDULER_DEPS) from airflow.utils import db as db_utils from airflow.utils.net import get_hostname from airflow.utils.log.logging_mixin import (LoggingMixin, redirect_stderr, - redirect_stdout, set_context) -from airflow.www.app import cached_app + redirect_stdout) +from airflow.www.app import (cached_app, create_app) from sqlalchemy import func from sqlalchemy.orm import exc @@ -694,7 +694,6 @@ def restart_workers(gunicorn_master_proc, num_workers_expected): def webserver(args): print(settings.HEADER) - app = cached_app(conf) access_logfile = args.access_logfile or conf.get('webserver', 'access_logfile') error_logfile = args.error_logfile or conf.get('webserver', 'error_logfile') num_workers = args.workers or conf.get('webserver', 'workers') @@ -713,10 +712,13 @@ def webserver(args): print( "Starting the web server on port {0} and host {1}.".format( args.port, args.hostname)) + app = create_app(conf) app.run(debug=True, port=args.port, host=args.hostname, ssl_context=(ssl_cert, ssl_key) if ssl_cert and ssl_key else None) else: - pid, stdout, stderr, log_file = setup_locations("webserver", args.pid, args.stdout, args.stderr, args.log_file) + app = cached_app(conf) + pid, stdout, stderr, log_file = setup_locations( + "webserver", args.pid, args.stdout, args.stderr, args.log_file) if args.daemon: handle = setup_logging(log_file) stdout = open(stdout, 'w+') http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/022b7ae3/tests/cli/test_cli.py ---------------------------------------------------------------------- diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py index 6db29cf..3b824a8 100644 --- a/tests/cli/test_cli.py +++ b/tests/cli/test_cli.py @@ -16,6 +16,7 @@ import unittest from mock import patch, Mock, MagicMock +from time import sleep import psutil @@ -57,3 +58,14 @@ class TestCLI(unittest.TestCase): with patch('psutil.Process', return_value=self.process): self.assertEqual(get_num_ready_workers_running(self.gunicorn_master_proc), 0) + + def test_cli_webserver_debug(self): + p = psutil.Popen(["airflow", "webserver", "-d"]) + sleep(3) # wait for webserver to start + return_code = p.poll() + self.assertEqual( + None, + return_code, + "webserver terminated with return code {} in debug mode".format(return_code)) + p.terminate() + p.wait()
