本文整理汇总了Python中openquake.job.Job类的典型用法代码示例。如果您正苦于以下问题:Python Job类的具体用法?Python Job怎么用?Python Job使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Job类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.generated_files = []
self.job = Job.from_file(test.do_test_file(CONFIG_FILE))
self.job_with_includes = Job.from_file(test.do_test_file(CONFIG_WITH_INCLUDES))
self.generated_files.append(self.job.super_config_path)
self.generated_files.append(self.job_with_includes.super_config_path)
示例2: setUp
def setUp(self):
self.generated_files = []
self.job = Job.from_file(helpers.get_data_path(CONFIG_FILE))
self.job_with_includes = \
Job.from_file(helpers.get_data_path(CONFIG_WITH_INCLUDES))
self.generated_files.append(self.job.super_config_path)
self.generated_files.append(self.job_with_includes.super_config_path)
示例3: test_is_job_completed
def test_is_job_completed(self):
job_id = Job.from_file(helpers.get_data_path(CONFIG_FILE), 'db').job_id
session = get_db_session("reslt", "writer")
pairs = [('pending', False), ('running', False),
('succeeded', True), ('failed', True)]
for status, is_completed in pairs:
session.query(OqJob).update({'status': status})
session.commit()
self.assertEqual(Job.is_job_completed(job_id), is_completed)
示例4: test_is_job_completed
def test_is_job_completed(self):
job_id = Job.from_file(helpers.get_data_path(CONFIG_FILE), 'db').job_id
row = OqJob.objects.get(id=job_id)
pairs = [('pending', False), ('running', False),
('succeeded', True), ('failed', True)]
for status, is_completed in pairs:
row.status = status
row.save()
self.assertEqual(Job.is_job_completed(job_id), is_completed)
示例5: test_get_status_from_db
def test_get_status_from_db(self):
self.job = Job.from_file(helpers.get_data_path(CONFIG_FILE), 'db')
session = get_db_session("reslt", "writer")
session.query(OqJob).update({'status': 'failed'})
session.commit()
self.assertEqual(Job.get_status_from_db(self.job.job_id), 'failed')
session.query(OqJob).update({'status': 'running'})
session.commit()
self.assertEqual(Job.get_status_from_db(self.job.job_id), 'running')
示例6: test_get_status_from_db
def test_get_status_from_db(self):
self.job = Job.from_file(helpers.get_data_path(CONFIG_FILE), 'db')
row = OqJob.objects.get(id=self.job.job_id)
row.status = "failed"
row.save()
self.assertEqual("failed", Job.get_status_from_db(self.job.job_id))
row.status = "running"
row.save()
self.assertEqual("running", Job.get_status_from_db(self.job.job_id))
示例7: test_prepares_blocks_using_the_exposure
def test_prepares_blocks_using_the_exposure(self):
a_job = Job({EXPOSURE: os.path.join(helpers.SCHEMA_EXAMPLES_DIR,
EXPOSURE_TEST_FILE)})
a_job._partition()
blocks_keys = a_job.blocks_keys
expected_block = job.Block((shapes.Site(9.15000, 45.16667),
shapes.Site(9.15333, 45.12200), shapes.Site(9.14777, 45.17999)))
self.assertEqual(1, len(blocks_keys))
self.assertEqual(expected_block, job.Block.from_kvs(blocks_keys[0]))
示例8: check_job_status
def check_job_status(job_id):
"""
Helper function which is intended to be run by celery task functions.
:raises JobCompletedError:
If :meth:`~openquake.job.Job.is_job_completed` returns ``True``
for ``job_id``.
"""
job = Job.from_kvs(job_id)
level = job.params.get('debug') if job and job.params else 'warn'
logs.init_logs_amqp_send(level=level, job_id=job_id)
if Job.is_job_completed(job_id):
raise JobCompletedError(job_id)
示例9: test_with_no_partition_we_just_process_a_single_block
def test_with_no_partition_we_just_process_a_single_block(self):
job.SITES_PER_BLOCK = 1
# test exposure has 6 assets
a_job = Job({EXPOSURE: os.path.join(test.DATA_DIR, EXPOSURE_TEST_FILE)})
self.generated_files.append(a_job.super_config_path)
a_job._partition()
blocks_keys = a_job.blocks_keys
# but we have 1 block instead of 6
self.assertEqual(1, len(blocks_keys))
示例10: test_prepares_blocks_using_the_exposure_and_filtering
def test_prepares_blocks_using_the_exposure_and_filtering(self):
a_job = Job({EXPOSURE: os.path.join(helpers.SCHEMA_EXAMPLES_DIR,
EXPOSURE_TEST_FILE),
INPUT_REGION: helpers.get_data_path(REGION_EXPOSURE_TEST_FILE)})
self.generated_files.append(a_job.super_config_path)
a_job._partition()
blocks_keys = a_job.blocks_keys
expected_block = job.Block((shapes.Site(9.15, 45.16667),
shapes.Site(9.15333, 45.122),
shapes.Site(9.14777, 45.17999)))
self.assertEqual(1, len(blocks_keys))
self.assertEqual(expected_block, job.Block.from_kvs(blocks_keys[0]))
示例11: test_prepares_blocks_using_the_input_region
def test_prepares_blocks_using_the_input_region(self):
""" This test might be currently catastrophically retarded. If it is
blame Lars.
"""
block_path = helpers.get_data_path(BLOCK_SPLIT_TEST_FILE)
print "In open job"
a_job = Job.from_file(block_path)
self.generated_files.append(a_job.super_config_path)
verts = [float(x) for x in a_job.params['REGION_VERTEX'].split(",")]
# Flips lon and lat, and builds a list of coord tuples
coords = zip(verts[1::2], verts[::2])
expected = shapes.RegionConstraint.from_coordinates(coords)
expected.cell_size = float(a_job.params['REGION_GRID_SPACING'])
expected_sites = []
for site in expected:
print site
expected_sites.append(site)
a_job._partition()
blocks_keys = a_job.blocks_keys
print blocks_keys
self.assertEqual(1, len(blocks_keys))
self.assertEqual(job.Block(expected_sites),
job.Block.from_kvs(blocks_keys[0]))
示例12: test_prepares_blocks_using_the_exposure
def test_prepares_blocks_using_the_exposure(self):
a_job = Job({EXPOSURE: os.path.join(test.DATA_DIR, EXPOSURE_TEST_FILE)})
a_job._partition()
blocks_keys = a_job.blocks_keys
expected_block = job.Block(
(
shapes.Site(9.15000, 45.16667),
shapes.Site(9.15333, 45.12200),
shapes.Site(9.14777, 45.17999),
shapes.Site(9.15765, 45.13005),
shapes.Site(9.15934, 45.13300),
shapes.Site(9.15876, 45.13805),
)
)
self.assertEqual(1, len(blocks_keys))
self.assertEqual(expected_block, job.Block.from_kvs(blocks_keys[0]))
示例13: check_job_status
def check_job_status(job_id):
"""
Helper function which is intended to be run by celery task functions.
:raises JobCompletedError:
If :meth:`~openquake.job.Job.is_job_completed` returns ``True``
for ``job_id``.
"""
if Job.is_job_completed(job_id):
raise JobCompletedError(job_id)
示例14: test_logs_a_warning_if_none_of_the_default_configs_exist
def test_logs_a_warning_if_none_of_the_default_configs_exist(self):
class call_logger(object):
def __init__(self, method):
self.called = False
self.method = method
def __call__(self, *args, **kwargs):
try:
return self.method(*args, **kwargs)
finally:
self.called = True
good_defaults = Job._Job__defaults
Job._Job__defaults = ["/tmp/sbfalds"]
LOG.warning = call_logger(LOG.warning)
self.assertFalse(LOG.warning.called)
Job.default_configs()
self.assertTrue(LOG.warning.called)
good_defaults = Job._Job__defaults
Job.__defaults = good_defaults
示例15: test_set_status
def test_set_status(self):
self.job = Job.from_file(helpers.get_data_path(CONFIG_FILE), 'db')
session = get_db_session("reslt", "writer")
status = 'running'
self.job.set_status(status)
job = session.query(OqJob).filter(OqJob.id == self.job.job_id).one()
self.assertEqual(status, job.status)