Add server starting option to manage.py.

This commit is contained in:
Arik Fraimovich
2014-01-17 11:23:06 +02:00
parent 806f57c627
commit 69f7c3417e
2 changed files with 20 additions and 14 deletions

View File

@@ -9,10 +9,10 @@ atfork.stdlib_fixer.fix_logging_module()
import argparse
import logging
import time
from redash import settings, data, redis_connection, data_manager
from redash import settings, app, data_manager
def start_workers(data_manager):
def start_workers():
try:
old_workers = data_manager.redis_connection.smembers('workers')
data_manager.redis_connection.delete('workers')
@@ -34,17 +34,32 @@ def start_workers(data_manager):
data_manager.stop_workers()
def start_server(port, debug):
app.run(debug=debug, port=port)
if __name__ == '__main__':
channel = logging.StreamHandler()
logging.getLogger().addHandler(channel)
logging.getLogger().setLevel(settings.LOG_LEVEL)
parser = argparse.ArgumentParser()
parser.add_argument("command")
subparsers = parser.add_subparsers(title='command', dest='command')
subparsers.add_parser('worker', help='start query execution workers')
server_parser = subparsers.add_parser('server', help='start api server')
server_parser.add_arguemnt('--debug',
action='store_true',
help='start in debug mode (code reload)')
server_parser.add_arguemnt('--port',
default=8888,
help='port to bind to')
args = parser.parse_args()
if args.command == "worker":
start_workers(data_manager)
start_workers()
elif args.command == 'server':
start_server(args.port, args.debug)
else:
print "Unknown command"

View File

@@ -1,17 +1,8 @@
"""
Flask-restful based API implementation for re:dash.
Also at the moment the Flask server is used to serve the static assets (and the Angular.js app),
Currently the Flask server is used to serve the static assets (and the Angular.js app),
but this is only due to configuration issues and temporary.
Usage:
python api.py [--port=8888] [--debug] [--static=..]
port - port to listen to
debug - enable debug mode (extensive logging, restart on code change)
static - static assets path
If static option isn't specified it will be taken from settings.py.
"""
import csv
import hashlib