Skip to content

django-crontab is missing job hash after one day #76

Closed
@LukBR

Description

@LukBR

I'm using django-crontab to run a function every day in my server. Everything seems to be ok when I add crons with python manage_local.py crontab add (I have a local manage.py) because I can see them running with crontab -l. Besides, I've tested both crons running them every minute and they executed properly.

So, the problem is when I run python manage_local.py crontab show on next day and it throws:

Currently active jobs in crontab:
Traceback (most recent call last):
  File "manage_local.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/gestordocsgic/ENV/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/gestordocsgic/ENV/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/gestordocsgic/ENV/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/gestordocsgic/ENV/lib/python3.5/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/home/gestordocsgic/ENV/lib/python3.5/site-packages/django_crontab/management/commands/crontab.py", line 24, in handle
    crontab.show_jobs()
  File "/home/gestordocsgic/ENV/lib/python3.5/site-packages/django_crontab/crontab.py", line 104, in show_jobs
    self.__get_job_by_hash(job[0][2][job[0][2].find('crontab run') + 12:].split()[0])
  File "/home/gestordocsgic/ENV/lib/python3.5/site-packages/django_crontab/crontab.py", line 173, in __get_job_by_hash
    'Run "python manage.py crontab add" again to resolve this issue!' % job_hash
RuntimeError: No job with hash 9223feb793825441cf3b87a2fa36072a found. It seems
the crontab is out of sync with your settings.CRONJOBS. Run "python manage.py crontab add" 
again to resolve this issue!

It seems like it loses the hash somehow from one day to another.

I have set CRONTAB_DJANGO_PROJECT_NAME and CRONTAB_DJANGO_MANAGE_PATH, but the problem is still there. This is my settings.py:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

CRONJOBS = [
('0 7 * * 1-5', 'api.cron.email_to_late_docs', '>> {}'.format(BASE_DIR + '/logs/log_{:%d_%m_%Y}.log'.format(time.now()))),
('0 7 * * 1-5', 'api.cron.email_ten_days_before', '>> {}'.format(BASE_DIR + 'logs/log_{:%d_%m_%Y}.log'.format(time.now())))
]

CRONTAB_DJANGO_PROJECT_NAME = 'public_html'
CRONTAB_DJANGO_MANAGE_PATH = BASE_DIR + '/manage_local.py'

Output of python manage_local.py crontab add:

  adding cronjob: (9223feb793825441cf3b87a2fa36072a) -> ('0 7 * * 1-5', 'api.cron.email_to_late_docs', '>> /home/gestordocsgic/public_html/logs/uca_09_05_2018.log')
  adding cronjob: (6c1dd239e0a8d3be61a2eb2440736fc6) -> ('0 7 * * 1-5', 'api.cron.email_ten_days_before', '>> /home/gestordocsgic/public_html/logs/uca_09_05_2018.log')

Output of crontab -l after adding cron:

0 7 * * 1-5 /home/gestordocsgic/ENV/bin/python /home/gestordocsgic/public_html/manage_local.py crontab run 9223feb793825441cf3b87a2fa36072a >> /home/gestordocsgic/public_html/logs/uca_09_05_2018.log # django-cronjobs for public_html
0 7 * * 1-5 /home/gestordocsgic/ENV/bin/python /home/gestordocsgic/public_html/manage_local.py crontab run 6c1dd239e0a8d3be61a2eb2440736fc6 >> /home/gestordocsgic/public_html/logs/uca_09_05_2018.log # django-cronjobs for public_html

I would appreciate any help!

Activity

kraiz

kraiz commented on May 9, 2018

@kraiz
Owner

Hi, the values within CRONJOBS are changing every day as you substitute the current day. This results in different job hashes. I recommend a stable name for your logs files.

LukBR

LukBR commented on May 14, 2018

@LukBR
Author

Hi! I've changed my log files as you suggested and it worked!

Thank you :)

iHTCboy

iHTCboy commented on Dec 13, 2018

@iHTCboy

-.- bug way can't Change to a variable file name? @kraiz

eswardhinak

eswardhinak commented on Jun 3, 2020

@eswardhinak

If someone has this issue, another similar problem is if your logfile uses a relative path. It's interpreted into an absolute path by cron (~/path/to/file gets translated to /home/ubuntu/path/to/file) which can change the hash as well.

nour-sidaoui

nour-sidaoui commented on Dec 24, 2020

@nour-sidaoui

how do I change cron logfile's location?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kraiz@eswardhinak@LukBR@iHTCboy@nour-sidaoui

        Issue actions

          django-crontab is missing job hash after one day · Issue #76 · kraiz/django-crontab