mirror of
https://github.com/LukeHagar/pypistats.dev.git
synced 2025-12-09 04:21:15 +00:00
docker setup; celery/beat config
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
"""PyPIStats application."""
|
||||
from celery import Celery
|
||||
from celery import Task
|
||||
from flask import Flask
|
||||
|
||||
from pypistats import views
|
||||
@@ -9,22 +11,29 @@ from pypistats.settings import DevConfig
|
||||
|
||||
|
||||
def create_app(config_object=DevConfig):
|
||||
"""Create the application.
|
||||
|
||||
:param config_object: The configuration object to use.
|
||||
"""
|
||||
app = Flask(__name__.split('.')[0])
|
||||
"""Create the application."""
|
||||
app = Flask(__name__.split(".")[0])
|
||||
app.config.from_object(config_object)
|
||||
register_extensions(app)
|
||||
register_blueprints(app)
|
||||
return app
|
||||
|
||||
|
||||
def register_extensions(app):
|
||||
"""Register Flask extensions."""
|
||||
db.init_app(app)
|
||||
github.init_app(app)
|
||||
migrate.init_app(app, db)
|
||||
def create_celery(app):
|
||||
"""Create a celery object."""
|
||||
celery = Celery(app.import_name, broker=app.config["CELERY_BROKER_URL"])
|
||||
celery.conf.update(app.config)
|
||||
celery.config_from_object(app.config)
|
||||
|
||||
class ContextTask(Task):
|
||||
abstract = True
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
with app.app_context():
|
||||
return Task.__call__(self, *args, **kwargs)
|
||||
|
||||
celery.Task = ContextTask
|
||||
return celery
|
||||
|
||||
|
||||
def register_blueprints(app):
|
||||
@@ -33,3 +42,10 @@ def register_blueprints(app):
|
||||
app.register_blueprint(views.error.blueprint)
|
||||
app.register_blueprint(views.general.blueprint)
|
||||
app.register_blueprint(views.user.blueprint)
|
||||
|
||||
|
||||
def register_extensions(app):
|
||||
"""Register Flask extensions."""
|
||||
db.init_app(app)
|
||||
github.init_app(app)
|
||||
migrate.init_app(app, db)
|
||||
|
||||
Reference in New Issue
Block a user