Skip to content

Instantly share code, notes, and snippets.

@ask
Forked from mikeywaites/async.py
Last active August 29, 2015 14:01
Show Gist options
  • Save ask/195e4229e9d5f1ff6a3d to your computer and use it in GitHub Desktop.
Save ask/195e4229e9d5f1ff6a3d to your computer and use it in GitHub Desktop.

Revisions

  1. ask revised this gist May 12, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion async.py
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ def configure_celery(flask_app):
    class ContextTask(celery.Task):
    abstract = True
    def __call__(self, *args, **kwargs):
    with flaskapp.app_context():
    with flask_app.app_context():
    return super(ContextTask, self).__call__(*args, **kwargs)
    celery.Task = ContextTask
    celery.finalize()
  2. ask revised this gist May 12, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions async.py
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,8 @@ def configure_celery(flask_app):
    class ContextTask(celery.Task):
    abstract = True
    def __call__(self, *args, **kwargs):
    with app.app_context():
    return TaskBase.__call__(self, *args, **kwargs)
    with flaskapp.app_context():
    return super(ContextTask, self).__call__(*args, **kwargs)
    celery.Task = ContextTask
    celery.finalize()

  3. ask revised this gist May 12, 2014. 1 changed file with 10 additions and 8 deletions.
    18 changes: 10 additions & 8 deletions async.py
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,28 @@
    #project.async
    celery = None
    from celery import Celery

    def make_celery(app):
    celery = Celery(autofinalize=False)


    def configure_celery(flask_app):
    #...set celery up
    global celery
    celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
    celery.conf.update(app.config)
    TaskBase = celery.Task
    class ContextTask(TaskBase):
    celery.config_from_object(app.config)

    class ContextTask(celery.Task):
    abstract = True
    def __call__(self, *args, **kwargs):
    with app.app_context():
    return TaskBase.__call__(self, *args, **kwargs)
    celery.Task = ContextTask
    celery.finalize()

    #project.__init__
    create_app(*kwargs):

    app = Flaks(__name__)
    db.init_app(app)

    make_celery(app)
    configure_celery(flask_app)

    #project.tasks
    from project.async import celery
  4. @mikeywaites mikeywaites revised this gist May 12, 2014. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions async.py
    Original file line number Diff line number Diff line change
    @@ -3,15 +3,24 @@

    def make_celery(app):
    #...set celery up
    celery = _celery
    global celery
    celery = Celery(app.import_name, broker=app.config['CELERY_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

    #project.__init__
    create_app(*kwargs):

    app = Flaks(__name__)
    db.init_app(app)


    make_celery(app)

    #project.tasks
    from project.async import celery
  5. @mikeywaites mikeywaites created this gist May 12, 2014.
    21 changes: 21 additions & 0 deletions async.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #project.async
    celery = None

    def make_celery(app):
    #...set celery up
    celery = _celery

    #project.__init__
    create_app(*kwargs):

    app = Flaks(__name__)
    db.init_app(app)



    #project.tasks
    from project.async import celery

    @celery.task
    def add(x, y):
    x + y