当我运行芹菜任务时我得到了这个。5.
[2021-10-29 19:08:18,216: INFO/MainProcess] Task update_orders[55790152-41c0-4d83-8874-4bd02754cb77] received
[2021-10-29 19:08:19,674: INFO/SpawnPoolWorker-8] child process 7196 calling self.run()
/
My celery.py
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from celery.schedules import crontab
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'src.settings.local')
BASE_REDIS_URL = os.environ.get('REDIS_URL', 'redis://localhost:6379')
app = Celery('src')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
app.conf.broker_url = BASE_REDIS_URL
@app.task(bind=True)
def debug_task(self):
print("Request: {0!r}".format(self.request))
app.conf.beat_scheduler = 'django_celery_beat.schedulers.DatabaseScheduler'
app.conf.worker_cancel_long_running_tasks_on_connection_loss = True
我tasks.py
import random
from celery import shared_task
from django.shortcuts import get_object_or_404
import datetime
from config.models import Config
@shared_task(name="update_orders")
def update_orders():
print('Delayed')
obj = Config.objects.all().order_by("-id").last()
obj.orders_last_time_updated = datetime.datetime.now()
obj.save()
return True
我的设置# CELERY STUFF
CELERY_BROKER_URL = 'redis://127.0.0.1:6379'
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = TIME_ZONE
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CELERY_RESULT_BACKEND = "django-db"
芹菜4.0+不正式支持窗口。但是对于一些开发/测试目的,它仍然可以在window上工作。
尝试安装gevent:
pip install gevent
然后运行
celery -A projectname worker -l info -P gevent
这适用于我的窗口10 +芹菜5.1.2 + python 3.10