本文整理汇总了Python中cms.grading.Job.JobGroup类的典型用法代码示例。如果您正苦于以下问题:Python JobGroup类的具体用法?Python JobGroup怎么用?Python JobGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JobGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_execute_job_subsequent_locked
def test_execute_job_subsequent_locked(self):
"""Executes a long job, then another one that should fail
because of the lock.
"""
# Because of how gevent works, the interval here can be very small.
task_type = FakeTaskType([0.01])
cms.service.Worker.get_task_type = Mock(return_value=task_type)
jobs_a, calls_a = TestWorker.new_jobs(1, prefix="a")
jobs_b, calls_b = TestWorker.new_jobs(1, prefix="b")
def first_call():
job_group = JobGroup([jobs_a[0]])
JobGroup.import_from_dict(
self.service.execute_job_group(job_group.export_to_dict()))
first_greenlet = gevent.spawn(first_call)
gevent.sleep(0) # To ensure we call jobgroup_a first.
with self.assertRaises(JobException):
job_group = JobGroup([jobs_b[0]])
JobGroup.import_from_dict(
self.service.execute_job_group(job_group.export_to_dict()))
first_greenlet.get()
self.assertNotIn(calls_b[0],
cms.service.Worker.get_task_type.mock_calls)
cms.service.Worker.get_task_type.assert_has_calls(calls_a)
示例2: test_execute_job_group_subsequent_locked
def test_execute_job_group_subsequent_locked(self):
"""Executes a job group with one long job, then another one
that should fail because of the lock.
"""
# Because of how gevent works, the interval here can be very small.
task_type = FakeTaskType([0.01])
cms.service.Worker.get_task_type = Mock(return_value=task_type)
jobgroup_a, calls_a = TestWorker.new_jobgroup(1, prefix="a")
jobgroup_b, calls_b = TestWorker.new_jobgroup(1, prefix="b")
def first_call():
JobGroup.import_from_dict(
self.service.execute_job_group(jobgroup_a.export_to_dict()))
first_greenlet = gevent.spawn(first_call)
gevent.sleep(0) # To ensure we call jobgroup_a first.
try:
JobGroup.import_from_dict(
self.service.execute_job_group(jobgroup_b.export_to_dict()))
except JobException:
# Expected
pass
else:
self.fail("Expected JobException from the lock.")
first_greenlet.get()
cms.service.Worker.get_task_type.assert_has_calls(
calls_a, any_order=True)
示例3: test_execute_job_group_subsequent_success
def test_execute_job_group_subsequent_success(self):
"""Executes a job group with three successful jobs, then another one.
"""
jobgroup_a, calls_a = TestWorker.new_jobgroup(3, prefix="a")
task_type_a = FakeTaskType([True, True, True])
cms.service.Worker.get_task_type = Mock(return_value=task_type_a)
JobGroup.import_from_dict(
self.service.execute_job_group(jobgroup_a.export_to_dict()))
cms.service.Worker.get_task_type.assert_has_calls(
calls_a, any_order=True)
self.assertEquals(task_type_a.call_count, 3)
jobgroup_b, calls_b = TestWorker.new_jobgroup(3, prefix="b")
task_type_b = FakeTaskType([True, True, True])
cms.service.Worker.get_task_type = Mock(return_value=task_type_b)
JobGroup.import_from_dict(
self.service.execute_job_group(jobgroup_b.export_to_dict()))
cms.service.Worker.get_task_type.assert_has_calls(
calls_b, any_order=True)
self.assertEquals(task_type_b.call_count, 3)
示例4: test_execute_job_group_failure_releases_lock
def test_execute_job_group_failure_releases_lock(self):
"""After a failure, the worker should be able to accept another job.
"""
jobgroup_a, calls_a = TestWorker.new_jobgroup(1)
task_type_a = FakeTaskType([Exception()])
cms.service.Worker.get_task_type = Mock(return_value=task_type_a)
try:
JobGroup.import_from_dict(
self.service.execute_job_group(jobgroup_a.export_to_dict()))
except JobException:
# Expected.
pass
else:
self.fail("Expected Jobexception from tasktype.")
cms.service.Worker.get_task_type.assert_has_calls(
calls_a, any_order=True)
self.assertEquals(task_type_a.call_count, 1)
jobgroup_b, calls_b = TestWorker.new_jobgroup(3)
task_type_b = FakeTaskType([True, True, True])
cms.service.Worker.get_task_type = Mock(return_value=task_type_b)
JobGroup.import_from_dict(
self.service.execute_job_group(jobgroup_b.export_to_dict()))
cms.service.Worker.get_task_type.assert_has_calls(
calls_b, any_order=True)
self.assertEquals(task_type_b.call_count, 3)
示例5: test_execute_job_group_success
def test_execute_job_group_success(self):
"""Executes a job group with three successful jobs.
"""
jobgroup, calls = TestWorker.new_jobgroup(3)
FakeTaskType.set_results([True] * 3)
cms.service.Worker.get_task_type = Mock(return_value=FakeTaskType())
JobGroup.import_from_dict(
self.service.execute_job_group(jobgroup.export_to_dict()))
cms.service.Worker.get_task_type.assert_has_calls(
calls, any_order=True)
示例6: test_execute_job_failure_releases_lock
def test_execute_job_failure_releases_lock(self):
"""After a failure, the worker should be able to accept another job.
"""
n_jobs_a = 1
jobs_a, calls_a = TestWorker.new_jobs(n_jobs_a)
task_type_a = FakeTaskType([Exception()])
cms.service.Worker.get_task_type = Mock(return_value=task_type_a)
with self.assertRaises(JobException):
job_group = JobGroup([jobs_a[0]])
JobGroup.import_from_dict(
self.service.execute_job_group(job_group.export_to_dict()))
cms.service.Worker.get_task_type.assert_has_calls(calls_a)
self.assertEquals(task_type_a.call_count, n_jobs_a)
n_jobs_b = 3
jobs_b, calls_b = TestWorker.new_jobs(n_jobs_b)
task_type_b = FakeTaskType([True] * n_jobs_b)
cms.service.Worker.get_task_type = Mock(return_value=task_type_b)
for job in jobs_b:
job_group = JobGroup([job])
JobGroup.import_from_dict(
self.service.execute_job_group(job_group.export_to_dict()))
cms.service.Worker.get_task_type.assert_has_calls(calls_b)
self.assertEquals(task_type_b.call_count, n_jobs_b)
示例7: test_execute_job_subsequent_success
def test_execute_job_subsequent_success(self):
"""Executes three successful jobs, then four others.
"""
n_jobs_a = 3
jobs_a, calls_a = TestWorker.new_jobs(n_jobs_a, prefix="a")
task_type_a = FakeTaskType([True] * n_jobs_a)
cms.service.Worker.get_task_type = Mock(return_value=task_type_a)
for job in jobs_a:
job_group = JobGroup([job])
JobGroup.import_from_dict(
self.service.execute_job_group(job_group.export_to_dict()))
cms.service.Worker.get_task_type.assert_has_calls(calls_a)
self.assertEquals(task_type_a.call_count, n_jobs_a)
n_jobs_b = 4
jobs_b, calls_b = TestWorker.new_jobs(n_jobs_b, prefix="b")
task_type_b = FakeTaskType([True] * n_jobs_b)
cms.service.Worker.get_task_type = Mock(return_value=task_type_b)
for job in jobs_b:
job_group = JobGroup([job])
JobGroup.import_from_dict(
self.service.execute_job_group(job_group.export_to_dict()))
cms.service.Worker.get_task_type.assert_has_calls(calls_b)
self.assertEquals(task_type_b.call_count, n_jobs_b)
示例8: test_execute_job_group_success
def test_execute_job_group_success(self):
"""Executes two successful job groups.
"""
n_jobs = [3, 3]
job_groups, calls = TestWorker.new_job_groups(n_jobs)
task_type = FakeTaskType([True] * sum(n_jobs))
cms.service.Worker.get_task_type = Mock(return_value=task_type)
for job_group in job_groups:
JobGroup.import_from_dict(
self.service.execute_job_group(job_group.export_to_dict()))
cms.service.Worker.get_task_type.assert_has_calls(calls)
self.assertEquals(task_type.call_count, sum(n_jobs))
示例9: test_execute_job_group_mixed_exceptions
def test_execute_job_group_mixed_exceptions(self):
"""Executes a job group with some exceptions.
"""
n_jobs = 4
expected_success = [True, Exception(), False, True]
self.assertEquals(n_jobs, len(expected_success))
job_groups, unused_calls = TestWorker.new_job_groups([n_jobs])
task_type = FakeTaskType(expected_success)
cms.service.Worker.get_task_type = Mock(return_value=task_type)
with self.assertRaises(JobException):
JobGroup.import_from_dict(
self.service.execute_job_group(job_groups[0].export_to_dict()))
示例10: test_execute_job_group_mixed_success
def test_execute_job_group_mixed_success(self):
"""Executes three job groups with mixed grades of success.
"""
n_jobs = [4, 4, 4]
expected_success = (
[True] * n_jobs[0] +
[False] + [True] * (n_jobs[1] - 1) +
[False] * n_jobs[2])
self.assertEquals(sum(n_jobs), len(expected_success))
job_groups, calls = TestWorker.new_job_groups(n_jobs)
task_type = FakeTaskType(expected_success)
cms.service.Worker.get_task_type = Mock(return_value=task_type)
results = []
for job_group in job_groups:
results.append(JobGroup.import_from_dict(
self.service.execute_job_group(job_group.export_to_dict())))
expected_idx = 0
for result in results:
for job in result.jobs:
self.assertIs(expected_success[expected_idx], job.success)
expected_idx += 1
cms.service.Worker.get_task_type.assert_has_calls(calls)
self.assertEquals(task_type.call_count, sum(n_jobs))
示例11: test_execute_job_tasktype_raise
def test_execute_job_tasktype_raise(self):
"""Executes two jobs raising exceptions.
"""
n_jobs = 2
jobs, unused_calls = TestWorker.new_jobs(n_jobs)
task_type = FakeTaskType([Exception(), Exception()])
cms.service.Worker.get_task_type = Mock(return_value=task_type)
for job in jobs:
with self.assertRaises(JobException):
job_group = JobGroup([job])
JobGroup.import_from_dict(
self.service.execute_job_group(job_group.export_to_dict()))
self.assertEquals(cms.service.Worker.get_task_type.call_count, n_jobs)
self.assertEquals(task_type.call_count, n_jobs)
示例12: test_execute_job_success
def test_execute_job_success(self):
"""Executes three successful jobs.
"""
n_jobs = 3
jobs, calls = TestWorker.new_jobs(n_jobs)
task_type = FakeTaskType([True] * n_jobs)
cms.service.Worker.get_task_type = Mock(return_value=task_type)
for job in jobs:
job_group = JobGroup([job])
ret_job_group = JobGroup.import_from_dict(
self.service.execute_job_group(job_group.export_to_dict()))
self.assertTrue(ret_job_group.jobs[0].success)
cms.service.Worker.get_task_type.assert_has_calls(calls)
self.assertEquals(task_type.call_count, n_jobs)
示例13: execute_job_group
def execute_job_group(self, job_group_dict):
"""Receive a group of jobs in a list format and executes them one by
one.
job_group_dict ({}): a JobGroup exported to dict.
return ({}): the same JobGroup in dict format, but containing
the results.
"""
start_time = time.time()
job_group = JobGroup.import_from_dict(job_group_dict)
if self.work_lock.acquire(False):
try:
logger.info("Starting job group.")
for job in job_group.jobs:
logger.info("Starting job.",
extra={"operation": job.info})
job.shard = self.shard
if self._fake_worker_time is None:
task_type = get_task_type(job.task_type,
job.task_type_parameters)
try:
task_type.execute_job(job, self.file_cacher)
except TombstoneError:
job.success = False
job.plus = {"tombstone": True}
else:
self._fake_work(job)
logger.info("Finished job.",
extra={"operation": job.info})
logger.info("Finished job group.")
return job_group.export_to_dict()
except Exception as e:
err_msg = "Worker failed: %s." % e
logger.error(err_msg, exc_info=True)
raise JobException(err_msg)
finally:
self._finalize(start_time)
self.work_lock.release()
else:
err_msg = "Request received, but declined because of acquired " \
"lock (Worker is busy executing another job, this should " \
"not happen: check if there are more than one ES running, " \
"or for bugs in ES."
logger.warning(err_msg)
self._finalize(start_time)
raise JobException(err_msg)
示例14: test_execute_job_group_tasktype_raise
def test_execute_job_group_tasktype_raise(self):
"""Executes a job group with three jobs raising exceptions.
"""
jobgroup, unused_calls = TestWorker.new_jobgroup(2)
FakeTaskType.set_results([Exception()] * 2)
cms.service.Worker.get_task_type = Mock(return_value=FakeTaskType())
try:
JobGroup.import_from_dict(
self.service.execute_job_group(jobgroup.export_to_dict()))
except JobException:
# Expected
pass
else:
self.fail("Expected JobException from the tasktype.")
# Does not continue after failure.
self.assertEquals(cms.service.Worker.get_task_type.call_count, 1)
示例15: test_execute_job_group_subsequent_success
def test_execute_job_group_subsequent_success(self):
"""Executes a job group with three successful jobs, then another one.
"""
jobgroup_a, calls_a = TestWorker.new_jobgroup(3)
FakeTaskType.set_results([True] * 3)
cms.service.Worker.get_task_type = Mock(return_value=FakeTaskType())
JobGroup.import_from_dict(
self.service.execute_job_group(jobgroup_a.export_to_dict()))
jobgroup_b, calls_b = TestWorker.new_jobgroup(3)
FakeTaskType.set_results([True] * 3)
JobGroup.import_from_dict(
self.service.execute_job_group(jobgroup_b.export_to_dict()))
cms.service.Worker.get_task_type.assert_has_calls(
calls_a + calls_b, any_order=True)