-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserver.py
31 lines (28 loc) · 1004 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import subprocess
from multiprocessing import cpu_count
from argparse import ArgumentParser
from fhir import create_app, db
from config import APP_CONFIG, HOST
# use this for WSGI server
# e.g. `$ gunicorn server:app`
app = create_app(APP_CONFIG)
def clear_db(app):
'''
Wipes the database associated with the app.
'''
with app.app_context():
db.drop_all()
db.create_all()
if __name__ == '__main__':
arg_parser = ArgumentParser()
arg_parser.add_argument('option', nargs='?', default='run', choices=('run', 'clear'))
arg_parser.add_argument('-d', '--debug', action='store_true')
args = arg_parser.parse_args()
if args.option == 'run':
if args.debug == True:
app.run(debug=True)
else:
num_workers = cpu_count() * 2 + 1
subprocess.call('gunicorn -w %d -b %s -D server:app --log-level error --log-file fhir.log'% (num_workers, HOST), shell=True)
elif args.option == 'clear':
clear_db(app)