我有一个periodic_task,如果我将crontab设置为每小时运行一次,它就有效。但是,如果我把它设置为像小时=" 13"分钟=" 5" (在下午1:05运行)它不起作用。问题可能出在时区配置中。我做错了吗?
settings.py
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Manila'
USE_I18N = True
USE_L10N = True
USE_TZ = True
celery_app.py
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
from celery.schedules import crontab
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'IrisOnline.settings')
app = Celery('IrisOnline', broker='redis://localhost:6379/0',include=[
"IrisOnline.tasks",
"order_management.tasks"
])
app.conf.update(
CELERY_TIMEZONE = 'Asia/Manila'
)
app.conf.update(
broker_url = 'redis://localhost:6379',
result_backend = 'redis://localhost:6379',
task_serializer='json',
accept_content=['json'],
result_serializer='json',
timezone='Asia/Manila',
)
app.conf.beat_schedule = {
'add-every-30-seconds': {
'task': 'IrisOnline.tasks.printthis',
'schedule':(crontab(hour=13,minute=33)),
},
}
# Using a string here means the worker don'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')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)