示例#1
0
文件: tasks.py 项目: kpanic/openquake
def get_running_calculation(calculation_id):
    """Helper function which is intended to be run by celery task functions.

    Given the id of an in-progress calculation
    (:class:`openquake.db.models.OqCalculation`), load all of the calculation
    data from the database and KVS and return a
    :class:`openquake.engine.CalculationProxy` object.

    If the calculation is not currently running, a
    :exception:`JobCompletedError` is raised.

    :returns:
        :class:`openquake.engine.CalculationProxy` object, representing an
        in-progress calculation. This object is created from cached data in the
        KVS as well as data stored in the relational database.
    :raises JobCompletedError:
        If :meth:`~openquake.engine.CalculationProxy.is_job_completed` returns
        ``True`` for ``calculation_id``.
    """
    # pylint: disable=W0404
    from openquake.engine import CalculationProxy

    if CalculationProxy.is_job_completed(calculation_id):
        raise JobCompletedError(calculation_id)

    calc_proxy = CalculationProxy.from_kvs(calculation_id)
    if calc_proxy and calc_proxy.params:
        level = calc_proxy.params.get('debug')
    else:
        level = 'warn'
    logs.init_logs_amqp_send(level=level, job_id=calculation_id)

    return calc_proxy
示例#2
0
 def test_is_job_completed(self):
     job_id = engine._job_from_file(helpers.get_data_path(CONFIG_FILE), "db").job_id
     row = OqCalculation.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(CalculationProxy.is_job_completed(job_id), is_completed)