예제 #1
0
 def test_normal_items(self):
     logging.info('+++++++++++++++++++++++++++ test normal items')
     cfg = ComposerConfig(runner_fn=self.runner_fn,
                          name='scheduler for normal items')
     composer = Composer(config=cfg)
     composer.run(db_engine=db.engine)
     normal_items = [Task(1), Task(2), Task(3)]
     name = 'normal items'
     composer.collect(name, normal_items, {})
     self.assertEqual(1, len(db.session.query(SchedulerItem).all()),
                      'incorrect items')
     # test unique item name
     composer.collect(name, normal_items, {})
     self.assertEqual(1, len(db.session.query(SchedulerItem).all()),
                      'incorrect items')
     time.sleep(20)
     self.assertEqual(1, len(db.session.query(SchedulerRunner).all()),
                      'incorrect runners')
     self.assertEqual(RunnerStatus.DONE.value,
                      composer.get_recent_runners(name)[-1].status,
                      'should finish runner')
     # finish item
     composer.finish(name)
     self.assertEqual(ItemStatus.OFF, composer.get_item_status(name),
                      'should finish item')
     composer.stop()
예제 #2
0
    def test_interval_items(self):
        logging.info(
            '+++++++++++++++++++++++++++ test finishing interval items')
        cfg = ComposerConfig(runner_fn=self.runner_fn,
                             name='finish normal items')
        composer = Composer(config=cfg)
        composer.run(db_engine=db.engine)
        name = 'cronjob'
        # test invalid interval
        self.assertRaises(ValueError,
                          composer.collect,
                          name, [Task(1)], {},
                          interval=9)

        composer.collect(name, [Task(1)], {}, interval=10)
        self.assertEqual(1, len(db.session.query(SchedulerItem).all()),
                         'incorrect items')
        time.sleep(20)
        self.assertEqual(2, len(db.session.query(SchedulerRunner).all()),
                         'incorrect runners')
        self.assertEqual(RunnerStatus.DONE.value,
                         composer.get_recent_runners(name)[-1].status,
                         'should finish runner')
        composer.finish(name)
        self.assertEqual(ItemStatus.OFF, composer.get_item_status(name),
                         'should finish item')
        composer.stop()
예제 #3
0
 def test_failed_items(self):
     logging.info('+++++++++++++++++++++++++++ test failed items')
     cfg = ComposerConfig(runner_fn=self.runner_fn,
                          name='scheduler for failed items')
     composer = Composer(config=cfg)
     composer.run(db_engine=db.engine)
     failed_items = [Task(4), Task(5), Task(6)]
     name = 'failed items'
     composer.collect(name, failed_items, {})
     self.assertEqual(1, len(db.session.query(SchedulerItem).all()),
                      'incorrect failed items')
     time.sleep(30)
     self.assertEqual(1, len(db.session.query(SchedulerRunner).all()),
                      'incorrect runners')
     self.assertEqual(RunnerStatus.FAILED.value,
                      composer.get_recent_runners(name)[-1].status,
                      'should finish it')
     composer.stop()
예제 #4
0
 def test_busy_items(self):
     logging.info('+++++++++++++++++++++++++++ test busy items')
     cfg = ComposerConfig(runner_fn=self.runner_fn,
                          name='scheduler for busy items',
                          worker_num=1)
     composer = Composer(config=cfg)
     composer.run(db_engine=db.engine)
     busy_items = [Task(7), Task(8), Task(9)]
     name = 'busy items'
     composer.collect(name, busy_items, {})
     self.assertEqual(1, len(db.session.query(SchedulerItem).all()),
                      'incorrect busy items')
     time.sleep(20)
     self.assertEqual(1, len(db.session.query(SchedulerRunner).all()),
                      'incorrect runners')
     self.assertEqual(RunnerStatus.RUNNING.value,
                      composer.get_recent_runners(name)[-1].status,
                      'should finish it')
     composer.stop()
     time.sleep(5)