kaka2507 / cron-validator

unix cron implementation in Python
MIT License
25 stars 9 forks source link

Scheduler & Scheduling Bug #3

Closed dprosperino closed 4 years ago

dprosperino commented 4 years ago

Hey!

I fixed the issue #2. The problem is basically that you assumed the week starts on a Monday which would mean MON = 0, TUE = 1, ..., SUN = 6. However, the official cron documentation states explicitely that their week starts on a Sunday meaning that SUN = 0, MON = 1, ..., SAT = 6. We should implement the offical mapping, since this package tries to imitate the official cron. Using a week starting on Monday would be only inconsistent and a cause for mistakes.

I closed the pull request #1, because the changes are in here too. I accidentally merged into my master and created a new branch from there meaning that both changes are in this pull request: The addition of a scheduler and the fix of the weekday bug.

Below you can read the contents of pull request #1:

I really like your package and the way you built it. Real smart programming there! I only missed one small feature, with which you can schedule tasks easily using a cron string. This pull request implements this feature, so you can schedule tasks as easy as:

from cron_validator import CronScheduler

cron_string = "*/1 * * * *"
scheduler = CronScheduler(cron_string)

while True:
    if scheduler.time_for_execution():
        # Get's called every full minute (excluding first iteration)
        print("Now is the next scheduled time.")

I also added testing for the part I contributed. It should work as expected. (I think you may have a bug in your code, but I'll open an issue on that on your repo.) (EDIT: Fixed!)

Lastly, I also updated the README and the versioning number. Hope that was okay.

Cheers! Davide

kaka2507 commented 4 years ago

Thank you for your contribution. I will take a look tmr and release.

kaka2507 commented 4 years ago

@dprosperino : Hi bro, I have released your patch as v1.0.2. Now, you can use it. Thank again for your great contribution.