django cron时间表不要重复

时间:2019-08-30 11:52:15

标签: django cron

我很难尝试根据guide设置Django cron计划。

settings.py:

INSTALLED_APPS = [
    'django_cron',
]

CRON_CLASSES = [
    "eventscalendar.cron.MyCronJob",
]

eventscalendar应用程序内的cron.py:

from django_cron import CronJobBase, Schedule
from eventscalendar.models import Subtask
import random

class MyCronJob(CronJobBase):
    frequency = 1
    schedule = Schedule(run_every_mins=frequency)
    code = 'eventscalendar.my_cron_job'

    def do(self):
        number = random.randint(1, 100)
        # save data to database
        add_records = Subtask(subtask_name='test' + str(number), subtask_description='test' + str(number))
        add_records.save()

问题:

  1. cron类仅在以下情况下初始化一次:python manage.py runcrons

谢谢您的时间。

0 个答案:

没有答案