This repository has been archived by the owner on Oct 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
factory.py
54 lines (42 loc) · 1.62 KB
/
factory.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
52
53
54
# -*- coding: utf-8 -*-
"""
overholt.factory
~~~~~~~~~~~~~~~~
overholt factory module
"""
import os
from celery import Celery
from flask import Flask
from flask_restful import Api
from helpers import register_blueprints
def create_app(package_name, package_path, settings_override=None,
register_security_blueprint=False):
"""Returns a :class:`Flask` application instance configured with common
functionality for the Overholt platform.
:param package_name: application package name
:param package_path: application package path
:param settings_override: a dictionary of settings to override
:param register_security_blueprint: flag to specify if the Flask-Security
Blueprint should be registered. Defaults
to `True`.
"""
app = Flask(package_name, instance_relative_config=True)
app.config.from_pyfile('settings.py', silent=False)
app.config.from_object(settings_override)
rv, apis =register_blueprints(app, package_name, package_path)
return app, apis
def create_celery_app(app=None):
if app is not None:
app = app
else:
app, apis = create_app('srv_queue', os.path.dirname(__file__))
celery = Celery(__name__, broker=app.config['SELERY_BROKER_URL'])
celery.conf.update(app.config)
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
celery.Task = ContextTask
return celery