CI, celery, compose setup, hackity hack hack
This commit is contained in:
@ -7,7 +7,9 @@ from redis import Redis
|
||||
|
||||
from magic_app.config import Base, Production
|
||||
|
||||
celery = Celery(__name__, broker=Base.CELERY_BROKER_URL)
|
||||
celery = Celery(
|
||||
__name__, backend=Base.CELERY_RESULT_BACKEND, broker=Base.CELERY_BROKER_URL
|
||||
)
|
||||
|
||||
|
||||
def create_app(config=Production):
|
||||
@ -15,8 +17,7 @@ def create_app(config=Production):
|
||||
app = Flask(__name__.split(".")[0])
|
||||
app.config.from_object(config)
|
||||
|
||||
celery.conf.update(app.config)
|
||||
|
||||
configure_celery(app)
|
||||
configure_redis(app)
|
||||
configure_views(app)
|
||||
configure_logging(app)
|
||||
@ -28,11 +29,11 @@ def configure_redis(app):
|
||||
"""Configure Redis connection."""
|
||||
from magic_app.session import RedisSessionDB
|
||||
|
||||
host = (Base.REDIS_HOST,)
|
||||
port = (Base.REDIS_PORT,)
|
||||
host = Base.REDIS_HOST
|
||||
port = Base.REDIS_PORT
|
||||
db_num = Base.REDIS_SESSION_DB
|
||||
|
||||
if app.debug:
|
||||
if app.testing:
|
||||
from fakeredis import FakeRedis
|
||||
|
||||
connection = FakeRedis()
|
||||
@ -42,6 +43,18 @@ def configure_redis(app):
|
||||
app.config["SESSION"] = RedisSessionDB(connection)
|
||||
|
||||
|
||||
def configure_celery(app):
|
||||
"""Configure celery."""
|
||||
celery.conf.update(app.config)
|
||||
|
||||
class ContextTask(celery.Task):
|
||||
def __call__(self, *args, **kwargs):
|
||||
with app.app_context():
|
||||
return self.run(*args, **kwargs)
|
||||
|
||||
celery.Task = ContextTask
|
||||
|
||||
|
||||
def configure_views(app):
|
||||
"""Configure API resource views."""
|
||||
from magic_app.views import home
|
||||
|
@ -25,14 +25,16 @@ class Development(Base):
|
||||
"""The Development configuration."""
|
||||
|
||||
ENV = "development"
|
||||
DEBUG = True
|
||||
|
||||
CELERY_ALWAYS_EAGER = True
|
||||
DEBUG = True
|
||||
|
||||
|
||||
class Testing(Base):
|
||||
"""The testing configuration."""
|
||||
|
||||
ENV = "testing"
|
||||
TESTING = True
|
||||
|
||||
|
||||
class Production(Base):
|
||||
|
@ -6,4 +6,5 @@ home = Blueprint("home", __name__)
|
||||
|
||||
@home.route("/")
|
||||
def hello_world():
|
||||
|
||||
return "Hello, World"
|
||||
|
Reference in New Issue
Block a user