dbader / schedule

Python job scheduling for humans.
https://schedule.readthedocs.io/
MIT License
11.73k stars 960 forks source link

Enhancement: can we get a every().working_day().do() ? #459

Closed Wissperwind closed 3 years ago

Wissperwind commented 3 years ago

Hi, I need do schedule a job every monday to friday at 10:00. Is there alread an option I missed? Can we get one?

Thanks!

anthonyzutter commented 3 years ago

I did this:

import datetime
day = datetime.datetime.today().weekday()
if day < 5:
    #schedule
else:
    print("Weekend")
Wissperwind commented 3 years ago

So you do the scheduling part yourself. Ok. But that is not the joke when using the schedule lib. I also need to cancel jobs. So I would need to schedule 5 jobs and make a special treetment for the cancellation because it needs to know that it has to cancle 5 jobs..

ojasww commented 3 years ago

While we can work on something like every().workday.do(), where the new workdays array in the library can be as: workdays = [ "monday", "tuesday", "wednesday", "thursday", "friday" ] I do not think schedule as a library is meant for that. Here is the doc link for reference: when not to use a schdule Moreover, workdays as a parameter are defined different from different organisations.

SijmenHuizenga commented 3 years ago

Hi! You could run a job daily and skip the execution on saturdays and sundays. This would look like this:

import schedule
import datetime

def job():
    # Monday is 0 and Friday is 4
    if datetime.datetime.today().weekday() > 4:
        return

    # do whatever needs to do
    pass

schedule.every().day.at("10:00").do(job)

If you have any more questions, feel free to open a new ticket :+1:

Wissperwind commented 3 years ago

Yes, I can use this workaround. I think it would improve the library to add it, but if you don't agree. It's your library. But thanks for the open discussion.