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
def test_can_store_and_read_jobs_from_kvs(self): flags_debug_default = flags.FLAGS.debug flags.FLAGS.debug = "debug" try: self.job = helpers.job_from_file(os.path.join(helpers.DATA_DIR, CONFIG_FILE)) job_from_kvs = CalculationProxy.from_kvs(self.job.job_id) self.assertEqual(flags.FLAGS.debug, job_from_kvs.params.pop("debug")) self.assertEqual(self.job, job_from_kvs) finally: helpers.cleanup_loggers() # Restore the default global FLAGS.debug level # so we don't break stuff. flags.FLAGS.debug = flags_debug_default