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//" In theextensions.py
file, theCelery
class from Flask-Celery-Helper will be initialized:
from flask.ext.celery import Celery celery = Celery()
So, in order for our Celery process to work with the database and any...