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

Schedule task on weekends or workweek #99

Open
msoedov opened this issue Oct 14, 2016 · 4 comments
Open

Schedule task on weekends or workweek #99

msoedov opened this issue Oct 14, 2016 · 4 comments

Comments

@msoedov
Copy link

msoedov commented Oct 14, 2016

That's would be very useful and I believe it's pretty common case

@dbader
Copy link
Owner

dbader commented Nov 7, 2016

Hi @msoedov 👋 I like the general idea but we could run into some trouble finding an international definition of "weekend" vs "workweek":

the weekend in Israel is observed on Friday–Saturday. Some Muslim-majority countries historically had a Thursday–Friday or Friday–Saturday weekend

(https://en.wikipedia.org/wiki/Workweek_and_weekend)

On the other hand I don't want to overcomplicate this either 😃 . My gut feeling would be that it's "safer" to ask people to spell out the schedule explicitly on a day by day basis.

Curious to hear your thoughts though!

~ Dan

@msoedov
Copy link
Author

msoedov commented Nov 7, 2016

I would suggest to implement "weekend" and "workweek" in the traditional meaning. For those who have exceptional cases like

Thursday–Friday or Friday–Saturday weekend

and believe it going to be less than 1% of users. Those can

spell out the schedule explicitly on a day by day basis.

@gregv21v
Copy link

I think it would be pretty easy for people to define their own weekend schedule.

@tompaton
Copy link

tompaton commented Apr 7, 2017

I would like something that did this for the cases when repeating the arguments to the job is messy.

How about an alternative Job factory (in addition to every()) that works as a generator and returns partially built Job instances. example usage:

for job in schedule.weekdays('monday', 'thursday'):
    job.at('7:45').do(something, arg1, arg2)

weekdays without arguments would default to 'monday', 'tuesday', 'wednesday', 'thursday', 'friday'.

A similar weekends method would default to 'saturday' and 'sunday'.

That would be very concise for the "default" case, and still completely customisable.

For now, I'm going to use the following helper in my project:

def schedule_weekdays(*days):
    for day in (days or ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']):
        job = schedule.every()
        yield getattr(job, day)

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

No branches or pull requests

4 participants