Open dxygit1 opened 3 months ago
I only get the correct behavior when I set USE_TZ to True, but I don't want to change USE_TZ to True.
➕1️⃣ I have a same question.
Configuration in my setting.py
file.
TIME_ZONE = "Asia/Shanghai"
USE_TZ = False
CELERY_TIMEZONE = TIME_ZONE
CELERY_ENABLE_UTC = False
DJANGO_CELERY_BEAT_TZ_AWARE = False
CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
def post(self, request: Request, *args, **kwargs):
PeriodicTask.objects.all().delete()
# 创建 IntervalSchedule
interval_schedule, created = IntervalSchedule.objects.get_or_create(
every=5, period=IntervalSchedule.SECONDS
)
# 计算结束时间
end_time = datetime.now() + timedelta(seconds=30)
# 创建PeriodicTask
periodic_task = PeriodicTask(
interval=interval_schedule,
name=f"periodic_task_{timezone.now()}",
task="publish.tasks.periodic_tasks",
args=json.dumps([1, 2]),
expires=end_time,
)
periodic_task.save()
return ApiResponse()
expires
this param is invalid
only support USE_TZ = True, to work properly
The last_run_at time is always in UTC, which differs from my local configuration time. This causes tasks to still run despite being expired.
version
config
Execute tasks.