Task not executed in Django's Celery

93 views Asked by At

Since I am not an English speaker, I use translation tools to write my text.

Task not executed Here are the execution environment and messages

Local PC

  • OS windows 10
  • Python 3.8

DB Server

  • CentOS 7.3
  • Redis 4.0.6
  • psql (PostgreSQL) 10.4
pip Package (relevant parts only)
Package                Version
celery                 5.2.7
Django                 3.2
django-celery-results  2.4.0
django-redis           5.2.0
redis                  4.1.1

*PROJECT\prj\settings.py

CELERY_BROKER_URL = 'redis://:' + REDIS_PASSWORD + '@' + REDIS_HOST + ':6379/1'
CELERY_RESULT_BACKEND = 'django-db'

CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['json']

CELERY_TIMEZONE = 'Asia/Tokyo'
CELERY_TASK_TRACK_STARTED = True
CELERY_TASK_TIME_LIMIT = 30 * 60

PROJECT\prj_init_.py

from .celery import app as celery_app
__all__ = ('celery_app',)

PROJECT\prj\celery.py

import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'prj.settings')
app = Celery('prj')
app.config_from_object('django.conf:settings', namespace="CELERY")
app.autodiscover_tasks()


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

PROJECT\common\task.py

from celery import shared_task

@shared_task
def load_croeds_csv(csv_file):
    print("start")

    print("end")
    return "ok"

PROJECT\manegements\view.py

class ProhibitedAreaCsvRegView(ContextRootStaff, FormView):
    template_name = 'manage/prohibited_area_csv.html'
    form_class = ProhibitedAreaCsvForm

    def get_context_data(self, **kwargs):
        context = super(ProhibitedAreaCsvRegView, self).get_context_data(**kwargs)
        title = ""
        context.update({
            'title': title,
            'form': self.form_class()
        })

        return context

    def form_valid(self, form):
        context = self.get_context_data(form=form)
        csv_file = form.cleaned_data["csv_file"]
        temp_path = save_csv_file(csv_file)
        result = load_croeds_csv.delay(temp_path)
        print(result.state)
        context.update({
            'result': result
        })
        return self.render_to_response(context=context)
(venv) PROJECT>celery -A prj worker -l info
 
 -------------- celery@HP1-USER10 v5.2.7 (dawn-chorus)
--- ***** -----
-- ******* ---- Windows-10-10.0.19045-SP0 2023-03-11 00:55:56
- *** --- * ---
- ** ---------- [config]
- ** ---------- .> app:         prj:0x1aa9732be20
- ** ---------- .> transport:   redis://:**@192.168.XXX.XXX:6379/1
- ** ---------- .> results:
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery


[tasks]
  . common.tasks.load_croeds_csv
  . configs.celery.debug_task

[2023-03-11 00:55:56,890: INFO/MainProcess] Connected to redis://:**@192.168.XX.XXX:6379/1

[2023-03-11 00:55:58,306: INFO/MainProcess] celery@HP1-USER10 ready.
[2023-03-11 00:56:12,928: INFO/MainProcess] Task common.tasks.load_croeds_csv[33f8c8e6-df97-4a7f-a4d5-b0286df934f3] received
[2023-03-11 00:56:14,218: INFO/SpawnPoolWorker-5] child process 3020 calling self.run()
[2023-03-11 00:56:14,226: INFO/SpawnPoolWorker-6] child process 15128 calling self.run()
[2023-03-11 00:56:14,246: INFO/SpawnPoolWorker-7] child process 12300 calling self.run()

>celery -A prj inspect scheduled 
->  celery@HP1-USER10: OK
    - empty -

DBserver redis

127.0.0.1:6379[1]> KEYS *
1) "_kombu.binding.celery.pidbox"
2) "unacked"
3) "unacked_index"
4) "_kombu.binding.celery"
5) "_kombu.binding.celeryev"

runserver

Watching for file changes with StatReloader
System check identified no issues (0 silenced).
March 11, 2023 - 00:55:48
Django version 3.2, using settings 'configs.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
PENDING

Processing does not complete after task is 'received'.

There are no tasks in django-celery-result in the admin.

What could be the cause?

0

There are 0 answers