Django: Getting Django-cron Running

后端 未结 1 1870
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 19:19

I am trying to get Django-cron running, but it seems to only run after hitting the site once. I am using Virtualenv.

Any ideas why it only runs once?

On my P

相关标签:
1条回答
  • 2020-12-21 19:34

    The first possible reason

    There is a variable in django_cron/base.py:

    # how often to check if jobs are ready to be run (in seconds)
    # in reality if you have a multithreaded server, it may get checked
    # more often that this number suggests, so keep an eye on it...
    # default value: 300 seconds == 5 min
    polling_frequency = getattr(settings, "CRON_POLLING_FREQUENCY", 300)
    

    So, the minimal interval of checking for time to start your task is polling_frequency. You can change it by setting in settings.py of your project:

    CRON_POLLING_FREQUENCY = 100 # use your custom value in seconds here
    

    To start a job hit your server at least one time after starting Django web server.

    The second possible reason

    Your job has an error and it is not queued (queued flag is set to 'f' if your job raises an exception). In this case it stores in field 'queued' of table 'django_cron_job' string value 'f'. You can test it making the query:

    select queued from django_cron_job;

    If you change the code of your job the field may stay as 'f'. So, if you correct the error of your job you should manually set in queued field: 't'. Or the flag executing in the table django_cron_cron is 't'. It means that your app. server was stopped when your task was in progress. In this case you should manually set it into 'f'.

    0 讨论(0)
提交回复
热议问题