Celery Funktion wird nicht aufgerufen

Django, Flask, Bottle, WSGI, CGI…
Antworten
nathy84
User
Beiträge: 1
Registriert: Dienstag 31. Juli 2018, 06:28

Ich versuche eine Progress Bar mit Celery zu erstellen. Leider wird meine Worker Funktion nie aufgerufen.
Jedenfalls sehe ich den Wert, welcher ich via Print ausgebe nie auf der Console.

celery.py

Code: Alles auswählen

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'devadmin.settings')

app = Celery('devadmin')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))
__init.py__

Code: Alles auswählen

from __future__ import absolute_import, unicode_literals

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app

__all__ = ('celery_app',)
views.py

Code: Alles auswählen

from celery import task, current_task
from celery.result import AsyncResult
from time import sleep

def checkconfig_post_new (request):
    job = do_work.delay()
    print ("Work started")
    return HttpResponseRedirect ( reverse ( 'poll_state' ) + '?job=' + job.id )

task.py

Code: Alles auswählen

from __future__ import absolute_import, unicode_literals
from celery import task, current_task
from time import sleep

# this decorator is all that's needed to tell celery this is a worker task
@task()
def do_work():
    """ Get some rest, asynchronously, and update the state all the time """
    for i in range(10):
        sleep(0.1)
        print (i)
        current_task.update_state(state='PROGRESS',
            meta={'current': i, 'total': 10})
Antworten