Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django crontab not executing test function

Tags:

python

django

I have following:

  1.   python manage.py crontab show # this command give following
    
      Currently active jobs in crontab:
      12151a7f59f3f0be816fa30b31e7cc4d -> ('*/1 * * * *', 'media_api_server.cron.cronSendEmail')
    
  2. My app is in virtual environment (env) active

  3. In my media_api_server/cron.py I have following function:

    def cronSendEmail():
        print("Hello")
        return true 
    
  4. In settings.py module:

    INSTALLED_APPS = (
        ......
        'django_crontab',
    )
    
    CRONJOBS = [
        ('*/1 * * * *', 'media_api_server.cron.cronSendEmail')
    ]
    

To me all defined in place but when I run python manage.py runserver in virtual environment, console doesn't print any thing.

    System check identified no issues (0 silenced).
    July 26, 2016 - 12:12:52
    Django version 1.8.1, using settings 'mediaserver.settings'
    Starting development server at http://127.0.0.1:8000/
    Quit the server with CONTROL-C.

'Django-crontab' module is not working I followed its documentation here https://pypi.python.org/pypi/django-crontab

like image 774
Jeevan Kumar Avatar asked Jul 26 '16 12:07

Jeevan Kumar


1 Answers

Your code actually works. You may be think that print("Hello") should appear in stdout? So it doesn't work that way, because cron doesn't use stdour and stderr for it's output. To see actual results you should point path to some log file in CRONJOBS list: just put '>> /path/to/log/file.log' as last argument, e.g:

CRONJOBS = [
    ('*/1 * * * *', 'media_api_server.cron.cronSendEmail', '>> /path/to/log/file.log')
]

Also it might be helpful to redirect your errors to stdout too. For this you heed to add CRONTAB_COMMAND_SUFFIX = '2>&1' to your settings.py

like image 131
valignatev Avatar answered Sep 28 '22 01:09

valignatev