Example #1
0
from flask_sqlalchemy import SQLAlchemy
import os
import shutil

app = Flask(__name__)

app.config["DEBUG"] = False
app.config["EPUB_FOLDER"] = os.path.join(os.path.dirname(os.path.abspath(__file__)), "epubs")

if os.path.isdir(app.config["EPUB_FOLDER"]):
    shutil.rmtree(app.config["EPUB_FOLDER"])

os.makedirs(app.config["EPUB_FOLDER"])

app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///webapp.db"
app.config["BROKER_TRANSPORT"] = "sqlakombu.transport.Transport"
app.config["BROKER_HOST"] = "sqlite:///celerydb.sqlite"
app.config["CELERY_BROKER_URL"] = "sqla+sqlite:///celerydb.sqlite"
app.config["CELERY_RESULT_BACKEND"] = "db+sqlite:///results.sqlite"

db = SQLAlchemy(app)


def make_celery(app):
    celery = Celery(
        app.import_name, broker=app.config["CELERY_BROKER_URL"], backend=app.config["CELERY_RESULT_BACKEND"]
    )
    celery.conf.update(app.config)
    TaskBase = celery.Task

    class ContextTask(TaskBase):
Example #2
0
    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


app = Flask(__name__, template_folder=settings.TEMPLATE_DIR)
app.config["CELERY_BROKER_URL"] = celeryconfig.BROKER_URL
app.config["CELERY_RESULT_BACKEND"] = celeryconfig.CELERY_RESULT_BACKEND
app.config["BROKER_TRANSPORT"] = celeryconfig.BROKER_TRANSPORT
app.config.update(
    CELERY_BROKER_URL="redis://localhost:6379",
    CELERY_RESULT_BACKEND="redis://localhost:6379",
    CELERY_IMPORTS=(app.import_name,),
)

async_celery = make_celery(app)


def mailer(data):
    from emailer import email_notifier

    print "Mailing: %s" % data
    category = data.get("category", None)
    author = data.get("author", None)