Пример #1
0
    def test_is_not_established_on_indicate_minute(self):
        j = Job('1,2,3 * * * *', action1)
        j.get_datetime = MagicMock(
            return_value=datetime(2020, 12, 23, 12, 0, 0))

        result = j.is_established()
        self.assertEqual(False, result)
Пример #2
0
    def test_is_established_every_minute(self):
        j = Job('* * * * *', action1)

        j.get_datetime = MagicMock(
            return_value=datetime(2020, 12, 23, 12, 0, 0))
        result = j.is_established()
        self.assertEqual(True, result)
Пример #3
0
 def test_is_established_on_divided_weekday(self):
     j = Job('* * * * */2', action1)
     expect_conditions = [0, 2, 4, 6]
     self.assertEqual(expect_conditions, j.weekday_conditions)
Пример #4
0
 def test_is_established_on_divided_month(self):
     j = Job('* * * */2 *', action1)
     expect_conditions = [2, 4, 6, 8, 10, 12]
     self.assertEqual(expect_conditions, j.month_conditions)
Пример #5
0
 def test_is_established_on_divided_day(self):
     j = Job('* * */2 * *', action1)
     expect_conditions = [
         2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
     ]
     self.assertEqual(expect_conditions, j.day_conditions)
Пример #6
0
 def test_is_established_on_divided_hour(self):
     j = Job('* */3 * * *', action1)
     expect_conditions = [0, 3, 6, 9, 12, 15, 18, 21]
     self.assertEqual(expect_conditions, j.hour_conditions)
Пример #7
0
    def test_is_established_on_divided_minute(self):
        j = Job('*/5 * * * *', action1)
        expect_conditions = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]

        self.assertEqual(expect_conditions, j.minute_conditions)
Пример #8
0
        super().__init__()
        self.scheduler = scheduler

    def run(self):
        while True:
            self.scheduler.run()


if __name__ == '__main__':

    csch = Scheduler()

    machines = [Machine(id) for id in range(1, 4)]

    commands = [SyncWithHardwareCommand(m) for m in machines]
    [csch.add_job(Job('* * * * *', c)) for c in commands]

    dbhandler = DBHandler()
    c = InsertAllMachineRecordToDatabaseCommand(machines, dbhandler)
    csch.add_job(Job('* * * * *', c))

    usch = Scheduler()
    usch.add_job(Job('*/3 * * * *', UploadUnuploadedRecords(dbhandler)))

    cthread = CollectorThread(csch)
    uthread = UploaderThread(usch)

    cthread.start()
    uthread.start()

    cthread.join()
Пример #9
0
from simplecron import Scheduler, Job


class Action1Command(object):
    def execute(self):
        print('action1 at {}'.format(datetime.now()))


class Action2Command(object):
    def execute(self):
        print('action2 at {}'.format(datetime.now()))
        

if __name__ == '__main__':
    s = Scheduler()
    s.add_job(Job('* * * * *', Action1Command()))
    s.add_job(Job('8,10,11,12 * * * *', Action2Command()))

    while True:
        s.run()

'''
$ python3 demo.py 
action1 at 2020-12-23 16:06:28.065473
action1 at 2020-12-23 16:07:28.065611
action2 at 2020-12-23 16:08:00.000023
action1 at 2020-12-23 16:08:28.065712
action1 at 2020-12-23 16:09:28.065797
action2 at 2020-12-23 16:10:00.000005
action1 at 2020-12-23 16:10:28.065891
action2 at 2020-12-23 16:11:00.000119
Пример #10
0
    def __init__(self, machines, dbhandler):
        self.machines = machines
        self.dbhandler = dbhandler
   
    def execute(self):
        for m in self.machines:
            r = m.get_record()
            self.dbhandler.insert_record(r)

        print('(DEBUG) InsertAllMachineRecordToDatabaseCommand.execute() at {}'.format(datetime.now()))



if __name__ == '__main__':

    s = Scheduler()

    machines = [Machine(id) for id in range(1,4)]

    commands = [SyncWithHardwareCommand(m) for m in machines]
    [s.add_job(Job('* * * * *', c)) for c in commands]

    dbhandler = DBHandler()
    c = InsertAllMachineRecordToDatabaseCommand(machines, dbhandler)
    s.add_job(Job('* * * * *', c))


    while True:
        s.run()