def test_schedule_task(self): """Jobs should be added and executed""" args = { 'uri': 'http://example.com/', 'gitpath': os.path.join(self.dir, 'data/git_log.txt') } category = 'commit' archive_args = {} sched_args = { 'delay': 0, 'max_retries_job': 0 } registry = TaskRegistry() task = registry.add('mytask', 'git', category, args, archive_args=archive_args, sched_args=sched_args) schlr = Scheduler(self.conn, registry, async_mode=False) job_id = schlr.schedule_task(task.task_id) schlr.schedule() job = schlr._scheduler._queues[Q_CREATION_JOBS].fetch_job(job_id) result = job.return_value self.assertEqual(result.last_uuid, '1375b60d3c23ac9b81da92523e4144abc4489d4c') self.assertEqual(result.max_date, 1392185439.0) self.assertEqual(result.nitems, 9)
def test_schedule_task(self): """Jobs should be added and executed""" args = {'uri': 'http://example.com/', 'gitpath': 'data/git_log.txt'} cache_args = {'cache_path': None, 'fetch_from_cache': False} sched_args = {'delay': 0, 'max_retries_job': 0} registry = TaskRegistry() task = registry.add('mytask', 'git', args, cache_args=cache_args, sched_args=sched_args) schlr = Scheduler(self.conn, registry, async_mode=False) job_id = schlr.schedule_task(task.task_id) schlr.schedule() job = schlr._scheduler._queues[Q_CREATION_JOBS].fetch_job(job_id) result = job.return_value self.assertEqual(result.last_uuid, '1375b60d3c23ac9b81da92523e4144abc4489d4c') self.assertEqual(result.max_date, 1392185439.0) self.assertEqual(result.nitems, 9)
def test_schedule_task(self): """Jobs should be added and executed""" args = { 'uri': 'http://example.com/', 'gitpath': os.path.join(self.dir, 'data/git_log.txt') } category = 'commit' archiving_opts = None scheduler_opts = SchedulingTaskConfig(delay=0, max_retries=0) registry = TaskRegistry() task = registry.add('mytask', 'git', category, args, archiving_cfg=archiving_opts, scheduling_cfg=scheduler_opts) schlr = Scheduler(self.conn, registry, async_mode=False) job_id = schlr.schedule_task(task.task_id) schlr.schedule() job = schlr._scheduler._queues[Q_CREATION_JOBS].fetch_job(job_id) result = job.return_value self.assertEqual(result.last_uuid, '1375b60d3c23ac9b81da92523e4144abc4489d4c') self.assertEqual(result.max_date, 1392185439.0) self.assertEqual(result.nitems, 9)
def test_set_job_number(self): """Check if the job number is set correctly when a new job is enqueued""" args = { 'uri': 'http://example.com/', 'gitpath': os.path.join(self.dir, 'data/git_log.txt') } category = 'commit' archiving_opts = None scheduler_opts = SchedulingTaskConfig(delay=0, max_retries=0, queue='myqueue') registry = TaskRegistry(self.conn) task = registry.add('mytask', 'git', category, args, archiving_cfg=archiving_opts, scheduling_cfg=scheduler_opts) schlr = Scheduler(self.conn, registry, async_mode=False) schlr.schedule_task(task.task_id) task = registry.get('mytask') self.assertEqual(task.status, TaskStatus.SCHEDULED) self.assertEqual(task.age, 0) # Modify the list of jobs to pretend this is not the first # time running this task. Job number will be calculated # adding one to the length of jobs. task.jobs = ['A', 'B', 'C'] registry.update('mytask', task) schlr = Scheduler(self.conn, registry, async_mode=False) schlr.schedule_task(task.task_id) task = registry.get('mytask') self.assertEqual(task.status, TaskStatus.SCHEDULED) self.assertEqual(task.age, 0) schlr.schedule() task = registry.get('mytask') self.assertEqual(task.age, 1) # Get the last job run and check the result job = schlr._scheduler._queues['myqueue'].fetch_job(task.jobs[3].id) result = job.return_value self.assertEqual(result.task_id, task.task_id) self.assertEqual(result.job_number, 4)
def test_add_job(self): """Jobs should be added and executed""" args = {'uri': 'http://example.com/', 'gitpath': 'data/git_log.txt'} repo = Repository('test', 'git', args, cache_path=None) schlr = Scheduler(self.conn, async_mode=False) job = schlr.add_job(Q_CREATION_JOBS, repo) result = job.return_value self.assertEqual(result.last_uuid, '1375b60d3c23ac9b81da92523e4144abc4489d4c') self.assertEqual(result.max_date, 1392185439.0) self.assertEqual(result.nitems, 9)
def test_add_job(self): """Jobs should be added and executed""" args = {'uri' : 'http://example.com/', 'gitpath' : 'data/git_log.txt'} repo = Repository('test', 'git', args, cache_path=None) schlr = Scheduler(self.conn, async_mode=False) job = schlr.add_job(Q_CREATION_JOBS, repo) result = job.return_value self.assertEqual(result.last_uuid, '1375b60d3c23ac9b81da92523e4144abc4489d4c') self.assertEqual(result.max_date, 1392185439.0) self.assertEqual(result.nitems, 9)
def test_not_found_task(self): """Raises an error when the task to schedule does not exist""" registry = TaskRegistry() schlr = Scheduler(self.conn, registry, async_mode=False) self.assertRaises(NotFoundError, schlr.schedule_task, 'mytask')
def test_not_found_queue(self): """Raises an error when a queue does not exist""" args = {'uri': 'http://example.com', 'gitpath': 'data/git_log.txt'} repo = Repository('test', 'git', args, cache_path=None) schlr = Scheduler(self.conn, async_mode=False) self.assertRaises(NotFoundError, schlr.add_job, 'myqueue', repo)
def test_queues_initialization(self): """Queues must be created""" schlr = Scheduler(self.conn, async_mode=False) self.assertIn(Q_CREATION_JOBS, schlr.queues) self.assertEqual(schlr.queues[Q_CREATION_JOBS]._async, False) self.assertIn(Q_UPDATING_JOBS, schlr.queues) self.assertEqual(schlr.queues[Q_UPDATING_JOBS]._async, False)
def test_schedule_task_user_queue(self): """Task should be added and executed in the user's queue""" args = { 'uri': 'http://example.com/', 'gitpath': os.path.join(self.dir, 'data/git_log.txt') } category = 'commit' archiving_opts = None scheduler_opts = SchedulingTaskConfig(delay=0, max_retries=0, queue='myqueue') registry = TaskRegistry() task = registry.add('mytask', 'git', category, args, archiving_cfg=archiving_opts, scheduling_cfg=scheduler_opts) schlr = Scheduler(self.conn, registry, async_mode=False) schlr.schedule_task(task.task_id) self.assertEqual(task.status, TaskStatus.SCHEDULED) self.assertEqual(task.age, 0) schlr.schedule() self.assertEqual(task.age, 1) job = schlr._scheduler._queues['myqueue'].fetch_job(task.jobs[0]) result = job.return_value self.assertEqual(result.task_id, task.task_id) self.assertEqual(result.last_uuid, '1375b60d3c23ac9b81da92523e4144abc4489d4c') self.assertEqual(result.max_date, 1392185439.0) self.assertEqual(result.nitems, 9)
def test_task_jobs_is_updated(self): """Test if the list of job ids for a task is updated""" args = { 'uri': 'http://example.com/', 'gitpath': os.path.join(self.dir, 'data/git_log.txt') } category = 'commit' archiving_opts = None scheduler_opts = SchedulingTaskConfig(delay=0, max_retries=0) registry = TaskRegistry() task = registry.add('mytask', 'git', category, args, archiving_cfg=archiving_opts, scheduling_cfg=scheduler_opts) schlr = Scheduler(self.conn, registry, async_mode=False) schlr.schedule_task(task.task_id) self.assertEqual(task.status, TaskStatus.SCHEDULED) self.assertEqual(task.age, 0) self.assertListEqual(task.jobs, []) schlr.schedule() self.assertEqual(task.age, 1) self.assertEqual(len(task.jobs), 1)
def test_schedule_task(self): """Jobs should be added and executed""" args = { 'uri': 'http://example.com/', 'gitpath': os.path.join(self.dir, 'data/git_log.txt') } category = 'commit' archiving_opts = None scheduler_opts = SchedulingTaskConfig(delay=0, max_retries=0) registry = TaskRegistry() task = registry.add('mytask', 'git', category, args, archiving_cfg=archiving_opts, scheduling_cfg=scheduler_opts) schlr = Scheduler(self.conn, registry, async_mode=False) schlr.schedule_task(task.task_id) self.assertEqual(task.status, TaskStatus.SCHEDULED) self.assertEqual(task.age, 0) schlr.schedule() self.assertEqual(task.age, 1) job = schlr._scheduler._queues[Q_CREATION_JOBS].fetch_job(task.jobs[0]) result = job.return_value self.assertEqual(result.task_id, task.task_id) self.assertEqual(result.job_number, 1) self.assertEqual(result.summary.last_uuid, '1375b60d3c23ac9b81da92523e4144abc4489d4c') self.assertEqual(result.summary.max_updated_on, datetime.datetime(2014, 2, 12, 6, 10, 39, tzinfo=UTC)) self.assertEqual(result.summary.total, 9)