Flask celery tasks not working Flask celery tasks not working flask flask

Flask celery tasks not working


I am not sure that this will help you but I am using this code on many of my projects when ever I need celery:

from flask import Flask, request, jsonify as jsnfrom celery import Celeryapp = Flask(__name__)app.config.update(dict(    SECRET_KEY='blabla'    ))# Celery configurationapp.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'app.config['CELERY_RESULT_BACKEND'] = 'database'app.config['CELERY_RESULT_DBURI'] = 'sqlite:///temp.db'app.config['CELERY_TRACK_STARTED'] = Trueapp.config['CELERY_SEND_EVENTS'] = True# Initialize Celerycelery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])celery.conf.update(app.config)@celery.taskdef do_something(data):    from celery import current_task    import os    import subprocess    with app.app_context():        #run some bash script with some params in my case

And then I am running celery with supervisor via:

#!/bin/bashcd /project/location && . venv/bin/activate && celery worker -A appname.celery --loglevel=info --purge #appname is my main flask file

And of course in my route i have somthing like

@app.route('/someroute', methods=["POST"])def someroute():    result = do_something.delay(data)    print result.id