Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LukBR opened this issue May 9, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@LukBR
Copy link

commented May 9, 2018

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!

@kraiz

This comment has been minimized.

Copy link
Owner

commented May 9, 2018

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

This comment has been minimized.

Copy link
Author

commented May 14, 2018

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

Thank you :)

@kraiz kraiz closed this May 14, 2018

@iHTCboy

This comment has been minimized.

Copy link

commented Dec 13, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.