Creating tasks in Celery

As stated before, Celery tasks are just user-defined functions that perform some operations. But before any tasks can be written, our Celery object needs to be created. This is the object that the Celery server will import to handle running and scheduling all of the tasks.

At a bare minimum, Celery needs one configuration variable to run: the connection to the message broker. The connection is defined like the SQLAlchemy connection, as a URL. The backend, what stores our tasks' results, is also defined as a URL as shown in the following code:

class DevConfig(Config): DEBUG = True SQLALCHEMY_DATABASE_URI = 'sqlite:///../database.db' CELERY_BROKER_URL = "amqp://guest:guest@localhost:5672//" CELERY_BACKEND = "amqp://guest:guest@localhost:5672//" ...

Get Flask: Building Python Web Services now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.