当前,我正在尝试使用芹菜和Redis安排任务,但我无法弄清楚如何在花朵中查看任务。 这些是我的配置文件。
local.yml `
version: '3'
volumes:
local_postgres_data: {}
local_postgres_data_backups: {}
services:
django: &django
build:
context: .
dockerfile: ./compose/local/django/Dockerfile
image: risky_dog_local_django
depends_on:
- postgres
- mailhog
- redis
links:
- redis
volumes:
- .:/app
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
ports:
- "8000:8000"
command: /start
postgres:
build:
context: .
dockerfile: ./compose/production/postgres/Dockerfile
image: risky_dog_production_postgres
volumes:
- local_postgres_data:/var/lib/postgresql/data
- local_postgres_data_backups:/backups
env_file:
- ./.envs/.local/.postgres
mailhog:
image: mailhog/mailhog:latest
ports:
- "8025:8025"
redis:
image: redis:3.2
celeryworker:
<<: *django
image: risky_dog_local_celeryworker
depends_on:
- redis
- postgres
- mailhog
links:
- redis
ports: []
command: /start-celeryworker
celerybeat:
<<: *django
image: risky_dog_local_celerybeat
depends_on:
- redis
- postgres
- mailhog
links:
- redis
ports: []
command: /start-celerybeat
flower:
<<: *django
image: risky_dog_local_flower
ports:
- "5555:5555"
command: /start-flower
`
models.py `
from django.contrib.auth.models import AbstractUser
from django.db.models import CharField
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from datetime import timedelta, datetime
from django.utils.timezone import now
from .tasks import send_bid_alert
class User(AbstractUser):
# First Name and Last Name do not cover name patterns
# around the globe.
name = CharField(_("Name of User"), blank=True, max_length=255)
def get_absolute_url(self):
return reverse("users:detail", kwargs={"username": self.username})
def save(self, *args, **kwargs):
super().save()
send_bid_alert.apply_async(eta=datetime.now() + timedelta(minutes=3))
`
tasks.py `
from __future__ import absolute_import, unicode_literals
from celery import shared_task
from django.utils import timezone
@shared_task
def send_bid_alert():
print("hello there")
result = 23
return result`
这些是我的配置文件。 我要实现的目标是,我创建了一个任务,并希望看到它与Flower配合使用。 目前,当我创建新用户时,这会立即在命令行中显示,但 我需要它在我的调度程序需要时显示。