Celery does not work with a bulb

I use celery in my flask application, but celery (3.1.8). This is my flask configuration

celery.py

 from __future__ import absolute_import
 from celery import Celery
 from cuewords.settings import CELERY_BROKER_URL,CELERY_RESULT_BACKEND

 app = Celery('proj',
         broker=CELERY_BROKER_URL,
         backend=CELERY_RESULT_BACKEND)

app.conf.update(CELERY_TASK_RESULT_EXPIRES=3600)

if __name__ == '__main__':
   app.start()

setting.py

  CELERY_BROKER_URL='redis://localhost:6379/0'
  CELERY_RESULT_BACKEND='redis://localhost:6379/0'
  BROKER_TRANSPORT = 'redis'

api.py

 class Webcontent(Resource):
   def post(self,session=session):
   args = self.parser.parse_args()
   site_url = args["url"]
   url_present=Websitecontent.site_url_present(session,site_url)
    if site_url.strip() != "" and not url_present:
      try:
        #add data and commit 
        session.commit()
        websitecontent=Websitecontent(params*)
        websitecontent.update_url(id,session)
      except:
        session.rollback()
      raise
      finally:
        session.close()                
    else:
      return "No data created / data already present"

And in my model I add a method for the task

model.py

  from cuewords.celery import app
  class Websitecontent(Base):

    @app.task(name='update_url')
    def update_url(self,id,session):
    ...code goes here..

And this is how I launch celery from the command line

celery -A cuewords.celery worker

And I also use a flower to control the task, I see how the worker works, but I could not see that any task was empty. Any idea that I have lost or am doing wrong. Thanks

+4
source share
1 answer

, Python (-). celery - . cuewords.celery, , . , , Python .

, Celery. , , . .

, Celery . :

from celery import Celery
from models import my_task

app = Celery()
app.task(name='my_task')(my_task)

.

. , , : http://docs.celeryproject.org/en/latest/reference/celery.contrib.methods.html. , . , . , , . , .

+7

Source: https://habr.com/ru/post/1527678/


All Articles