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

Weekly job executing after 6 days instead of 7 #2426

Closed
joaopsys opened this issue Sep 15, 2022 · 3 comments · Fixed by #2670
Closed

Weekly job executing after 6 days instead of 7 #2426

joaopsys opened this issue Sep 15, 2022 · 3 comments · Fixed by #2670
Assignees
Labels
type: bug Something isn't working as expected

Comments

@joaopsys
Copy link
Contributor

Environment

  • Nautobot version (Docker tag too if applicable): 1.4.2
  • Python version: 3.8.13

Steps to Reproduce

  1. Schedule a weekly job in Nautobot
  2. Let the job run twice
  3. Notice how the difference between executions was only 6 days, instead of 7 days

Maybe there's a reason for this that I am just not seeing, but I fully expected my weekly job to execute exactly 7 days after the previous run, and not 6 days.

Check the following screenshot. I have a couple more jobs that behaved the same, i.e. executed after 6 days and not 7.

weekly-job-6-days

@lampwins
Copy link
Member

@nautobot/core can we have someone setup a test to try to reproduce this?

@lampwins lampwins added the question Further information is requested label Sep 27, 2022
@gsnider2195
Copy link
Contributor

Confirmed. The scheduled job to_cron method is passing datetime.datetime.weekday() to celery.schedules.crontab.day_of_week

datetime.datetime.weekday:

Monday = 0

 |  weekday(...)
 |      Return the day of the week represented by the date.
 |      Monday == 0 ... Sunday == 6

celery.schedules.crontab.day_of_week:

Sunday = 0

     |  .. attribute:: day_of_week
     |  
     |      - A (list of) integers from 0-6, where Sunday = 0 and Saturday =
     |        6, that represent the days of a week that execution should
     |        occur.
     |      - A string representing a Crontab pattern.  This may get pretty
     |        advanced, like ``day_of_week='mon-fri'`` (for weekdays only).
     |        (Beware that ``day_of_week='*/2'`` does not literally mean
     |        'every two days', but 'every day that is divisible by two'!)
     |  

@gsnider2195 gsnider2195 added type: bug Something isn't working as expected and removed question Further information is requested labels Sep 27, 2022
@gsnider2195
Copy link
Contributor

gsnider2195 commented Sep 28, 2022

day_of_week = (t.weekday() + 1) % 7

Here?

Another option

return schedules.crontab(minute=t.minute, hour=t.hour, day_of_week=t.strftime("%w"))

@gsnider2195 gsnider2195 self-assigned this Oct 21, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants