Exemple #1
0
def run_hazard_job(cfg, exports=None):
    """
    Given the path to job config file, run the job and assert that it was
    successful. If this assertion passes, return the completed job.

    :param str cfg:
        Path to a job config file.
    :param list exports:
        A list of export format types. Currently only 'xml' is supported.
    :returns:
        The completed :class:`~openquake.engine.db.models.OqJob`.
    """
    if exports is None:
        exports = []

    job = get_hazard_job(cfg)
    job.is_running = True
    job.save()

    models.JobStats.objects.create(oq_job=job)

    hc = job.hazard_calculation
    calc = get_calculator_class('hazard', hc.calculation_mode)(job)
    try:
        logs.init_logs_amqp_send(
            level='ERROR', calc_domain='hazard', calc_id=hc.id)
        engine._do_run_calc(job, exports, calc, 'hazard')
    finally:
        job.is_running = False
        job.calc = calc
        job.save()
    return job
Exemple #2
0
    def test_do_run_calc(self):
        with helpers.MultiMock(
                sj='openquake.engine.engine._switch_to_job_phase'):
            progress_handler = mock.Mock()
            calc = self.FakeCalc(mock.Mock())
            calc.register_progress_handler(progress_handler)

            engine._do_run_calc(calc.job, [], calc, "hazard")

        self.assertTrue(progress_handler.call_count > 0)
        self.assertEqual((('calculation complete', self.FakeCalc.hc), {}),
                         progress_handler.call_args)
Exemple #3
0
def run_risk_job(cfg, exports=None, hazard_calculation_id=None,
                 hazard_output_id=None):
    """
    Given the path to a risk job config file and a hazard_calculation_id
    or a output, run the job.
    """
    if exports is None:
        exports = []

    # You can't specify both a hazard output and hazard calculation
    # Pick one
    assert not (hazard_calculation_id is not None
                and hazard_output_id is not None)

    job = get_risk_job(cfg, hazard_calculation_id=hazard_calculation_id,
                       hazard_output_id=hazard_output_id)
    job.is_running = True
    job.save()

    models.JobStats.objects.create(oq_job=job)

    rc = job.risk_calculation
    calc = get_calculator_class('risk', rc.calculation_mode)(job)
    logs.init_logs_amqp_send(level='ERROR', calc_domain='risk', calc_id=rc.id)
    completed_job = engine._do_run_calc(job, exports, calc, 'risk')
    job.is_running = False
    job.save()

    return completed_job