~yerinalexey/pcrond

a000241ed17efab1bd8ed38434771ec8a6a7b546 — Luca Vercelli 2 years ago a4cfffb
using Python weekdays
2 files changed, 13 insertions(+), 8 deletions(-)

M pcrond/job.py
M test_scheduler.py
M pcrond/job.py => pcrond/job.py +10 -6
@@ 84,9 84,13 @@ class Job(object):
                                  and len(self.allowed_dow) > 0
                                  and min(self.allowed_dow) < 0)

        self.must_consider_w = (self.allowed_dow is not None
                                and len(self.allowed_dow) > 0
                                and min(self.allowed_dow) >= 7)
        # warning: in Python, Monday is 0 and Sunday is 6
        #          in cron, Sunday=0
        if self.allowed_dow:
            t1 = set([(x + 6) % 7 for x in self.allowed_dow if x >= 0])
            t2 = set([(x + 13) % 7 for x in self.allowed_dow if x < 0])
            self.allowed_dow = t1
            self.allowed_dowl = t2

        self.crontab_pattern = crontab_lst



@@ 251,10 255,10 @@ class Job(object):
                and (self.allowed_every_hour or now.hour in self.allowed_hours)
                and (self.allowed_every_min or now.minute in self.allowed_min)
                and (self.allowed_every_dow
                     or ((now.weekday() + 1) % 7) in self.allowed_dow
                     or (now.weekday() in self.allowed_dow
                     or (self.must_consider_wom
                         and (now.weekday() - 6) in self.allowed_dow
                         and self.is_last_wom(now)))
                         and now.weekday() in self.allowed_dowl
                         and self.is_last_wom(now))))
                and (self.allowed_every_dom
                     or now.day in self.allowed_dom
                     or (self.allowed_last_dom and now.day == self.get_last_dom(now)))

M test_scheduler.py => test_scheduler.py +3 -2
@@ 86,7 86,7 @@ class SchedulerTests(unittest.TestCase):
        assert job.allowed_months == set([3, 4, 5, 6, 12])
        ###
        assert not job.allowed_every_dow
        assert job.allowed_dow == set([1])
        assert job.allowed_dow == set([0])             # 1 in cron, 0 in python
        ###
        assert job.allowed_every_year



@@ 104,7 104,8 @@ class SchedulerTests(unittest.TestCase):
        assert job.allowed_every_dom
        assert not job.allowed_last_dom
        assert not job.allowed_every_dow
        assert job.allowed_dow == set([5-7])
        assert not job.allowed_dow
        assert job.allowed_dowl == set([4])             # 5 in cron, 4 in python
        assert job._should_run_at(d(2019, 3, 29))       # was fri
        assert not job._should_run_at(d(2019, 3, 28))   # was thu
        assert not job._should_run_at(d(2019, 3, 8))    # was fri