GithubHelp home page GithubHelp logo

longpham-betall / flask-celery Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ask/flask-celery

0.0 1.0 0.0 167 KB

Celery integration for Flask (SINCE CELERY 3.0 THIS IS NO LONGER NEEDED)

Home Page: http://celeryproject.org

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

flask-celery's Introduction

Flask <-> Celery Integration

Version: 2.4.3

FROM CELERY 3.0 THIS LIBRARY IS NO LONGER NECESSARY, INSTEAD YOU SHOULD USE THE STANDARD CELERY API

Using Flask with Celery

From Celery 3.0 the Flask-Celery integration package is no longer recommended and you should use the standard Celery API instead.

Please read the Celery getting started tutorial:

http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html

You can easily add Celery to your flask application like this:

myapp.py:

from celery import Celery

celery = Celery('myapp', broker='amqp://guest@localhost//')

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

To start the worker you can then launch the celery worker command by pointing to your celery app instance:

$ celery -A myapp:celery worker -l info

See the commands help screen for more information:

$ celery help

If you want use the flask configuration as a source for the celery configuration you can do that like this:

celery = Celery('myapp')
celery.conf.add_defaults(app.config)

If you need access to the request inside your task then you can use the test context:

from flask import Flask
from celery import Celery

app = Flask('myapp')
celery = Celery('myapp')
celery.conf.add_defaults(app.config)

@celery.task
def hello():
    with app.test_request_context() as request:
        print('Hello {0!r}.format(request))

flask-celery's People

Contributors

ask avatar coderanger avatar gldnspud avatar jpvanhal avatar khakimov avatar rduplain avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.