-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
40 lines (34 loc) · 1.45 KB
/
app.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
32
33
34
35
36
37
38
39
40
from flask import Flask
from src.controllers.content_controller import content_bp
from src.controllers.search_controller import search_bp
from src.controllers.health_controller import health_bp
from src.controllers.api_key_controller import api_key_bp
from src.events.search_requested_handler import SearchRequestedHandler
from src.events.indexer_started_handler import IndexerStartedHandler
import os
import atexit
import logging
from apscheduler.schedulers.background import BackgroundScheduler
# set flask app
app = Flask(__name__)
# register blueprints (controllers)
app.register_blueprint(content_bp)
app.register_blueprint(search_bp)
app.register_blueprint(health_bp)
app.register_blueprint(api_key_bp)
# start server
if __name__ == "__main__":
# setup scheduler to read from redis queue
scheduler = BackgroundScheduler()
scheduler.remove_all_jobs()
scheduler.add_job(func=SearchRequestedHandler.listen, id='redis_subs', max_instances=1)
scheduler.add_job(func=IndexerStartedHandler.listen, id='redis_indexer', max_instances=1)
scheduler.start()
# Shut down the scheduler when exiting the app
atexit.register(lambda: scheduler.shutdown())
# set logging level to display logs from apscheduler
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('apscheduler').setLevel(logging.DEBUG)
# run flask app
port = int(os.environ.get('PORT', 5000))
app.run(debug=True, host='0.0.0.0', port=port, use_reloader=False)