def test_failed_tasks_saved(self): boss.start(action=failed_action) for i in range(10): task = boss.Task(i, {}) boss.assign_task(task) total_check = 0 while not boss.have_all_tasks_done(): time.sleep(1) total_check += 1 if total_check > 10: self.fail('workers have not stpped in time') boss.stop() for k, v in boss.tasks().items(): self.assertTrue(v.is_failed())
def test_boss_can_shut_down(self): boss.start(action=half_done_half_failed_action) for i in range(10): task = boss.Task(i, {}) boss.assign_task(task) total_check = 0 while not boss.have_all_tasks_done(): time.sleep(1) total_check += 1 if total_check > 10: self.fail('workers have not stpped in time') boss.stop() for t in boss._WORKING_THREADS: self.assertFalse(t.isAlive())
def run(self): try: boss.start(num_workers=self.num_worker, action=streambot._download_task_action) self._get_mpd() if self.mpd.is_live(): self._get_live_segments() else: self._get_segments() while not boss.have_all_tasks_done(): time.sleep(1) except Exception as e: logger.exception(e) finally: boss.stop() self._report()
def test_duplicated_tasks_run_only_once(self): boss.start(action=half_done_half_failed_action) num_unique_tasks = 10 for i in range(num_unique_tasks): task = boss.Task(i, {}) # assign each task twice boss.assign_task(task) boss.assign_task(task) total_check = 0 while not boss.have_all_tasks_done(): time.sleep(1) total_check += 1 if total_check > 10: self.fail('workers have not stpped in time') boss.stop() self.assertEqual(len(boss.tasks()), num_unique_tasks)
def test_tasks_returns_all_assigned_tasks(self): boss.start(action=done_action) num_tasks = 10 for i in range(num_tasks): task = boss.Task(i, {}) boss.assign_task(task) total_check = 0 while not boss.have_all_tasks_done(): time.sleep(1) total_check += 1 if total_check > 10: self.fail('workers have not stpped in time') boss.stop() assigned_tasks = boss.tasks() self.assertTrue(len(assigned_tasks), num_tasks) for k, v in boss.tasks().items(): self.assertTrue(v.id in range(num_tasks))
def start(num_workers=2): boss.blocking_print('Start downloader with {i} workers'.format(i=num_workers)) boss.start(num_workers=num_workers, task_processor=_download_task)
def start(num_workers=2): boss.blocking_print( 'Start downloader with {i} workers'.format(i=num_workers)) boss.start(num_workers=num_workers, task_processor=_download_task)