forked from harvard-lil/alter-space
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
51 lines (34 loc) · 1.27 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
41
42
43
44
45
46
47
48
49
50
51
import os
import logging
from flask import Flask
from flask_cors import CORS
from backend.views import backend_app
from backend import tasks
from config import config
logging.basicConfig(filename=config.LOG_FILENAME, format=config.LOG_FORMAT, level=config.LOG_LEVEL)
logger = logging.getLogger()
def configure_celery(app, celery):
celery.conf.broker_url = app.config['CELERY_BROKER_URL']
celery.conf.result_backend = app.config['CELERY_RESULT_BACKEND']
TaskBase = celery.Task
class ContextTask(TaskBase):
def __call__(self, *args, **kwargs):
with app.app_context():
return self.run(*args, **kwargs)
celery.Task = ContextTask
# run finalize to process decorated tasks
celery.finalize()
def configure_app(app):
logger.info('configuring flask app')
app.config.from_pyfile(os.path.join(config.DIR, 'config/config.py'))
def create_app():
template_folder = os.path.join(config.DIR, "dist")
app = Flask(__name__,
static_url_path='/static',
static_folder=os.path.join(template_folder, "static"),
template_folder=template_folder)
configure_app(app)
configure_celery(app, tasks.celery)
app.register_blueprint(backend_app)
CORS(app)
return app