I'm trying to get Flask to work with Celery with SQLite as backend. With the following code, however:
CELERY_BROKER_URL = 'sqla+sqlite:///' + os.path.join(basedir, 'celery.db')
def make_celery(app):
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
return celery
After starting a worker, I get this error when trying to call a dummy task:
error: [Errno 10061] No connection could be made because the target machine actively refused it
Code:
@app.route('/test')
def test():
t = add_together.delay(100,200)
return str(t.wait())
What's wrong? I've tried googling any combination of Sqllite/SQLAlchemy/Flask/Celery, but have been unable to find a solution.
As you can see in your trace, your app still trying to connect to rabbitmq-server. That means it's not configured properly. I didn't get why you're using CELERY_BROKER_URL
instead of BROKER_URL
. Quick solution may be, change this:
celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
to
celery = Celery(app.import_name,
broker='sqla+sqlite:///' + os.path.join(basedir, 'celery.db'),
backend='db+sqlite:///' + os.path.join(basedir, 'celery_results.db'))
Let's check how it works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With