Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/api/server.py
# Copyright (C) 2018 The Software Heritage developers | # Copyright (C) 2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import logging | import logging | ||||
import click | |||||
from flask import request | from flask import request | ||||
from swh.core import config | from swh.core import config | ||||
from swh.scheduler import get_scheduler as get_scheduler_from | from swh.scheduler import get_scheduler as get_scheduler_from | ||||
from swh.core.api import (SWHServerAPIApp, decode_request, | from swh.core.api import (SWHServerAPIApp, decode_request, | ||||
error_handler, | error_handler, | ||||
encode_data_server as encode_data) | encode_data_server as encode_data) | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | def run_from_webserver(environ, start_response, | ||||
"""Run the WSGI app from the webserver, loading the configuration.""" | """Run the WSGI app from the webserver, loading the configuration.""" | ||||
cfg = config.load_named_config(config_path, DEFAULT_CONFIG) | cfg = config.load_named_config(config_path, DEFAULT_CONFIG) | ||||
app.config.update(cfg) | app.config.update(cfg) | ||||
handler = logging.StreamHandler() | handler = logging.StreamHandler() | ||||
app.logger.addHandler(handler) | app.logger.addHandler(handler) | ||||
return app(environ, start_response) | return app(environ, start_response) | ||||
@click.command() | |||||
@click.argument('config-path', required=1) | |||||
@click.option('--host', default='0.0.0.0', | |||||
help="Host to run the scheduler server api") | |||||
@click.option('--port', default=5008, type=click.INT, | |||||
help="Binding port of the server") | |||||
@click.option('--debug/--nodebug', default=True, | |||||
help="Indicates if the server should run in debug mode") | |||||
def launch(config_path, host, port, debug): | |||||
app.config.update(config.read(config_path, DEFAULT_CONFIG)) | |||||
app.run(host, port=port, debug=bool(debug)) | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
launch() | print('Please use the "swh-scheduler api-server" command') |