def get_running_job(job_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.OqJob`), load all of the calculation data from the database and KVS and return a :class:`openquake.engine.JobContext` object. If the calculation is not currently running, a :exc:`JobCompletedError` is raised. :returns: :class:`openquake.engine.JobContext` object, representing an in-progress job. 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.JobContext.is_job_completed` returns ``True`` for ``job_id``. """ # pylint: disable=W0404 from openquake.engine import JobContext if JobContext.is_job_completed(job_id): raise JobCompletedError(job_id) job_ctxt = JobContext.from_kvs(job_id) if job_ctxt and job_ctxt.params: level = job_ctxt.log_level else: level = 'warn' logs.init_logs_amqp_send(level=level, job_id=job_id) return job_ctxt
def get_running_job(job_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.OqJob`), load all of the calculation data from the database and KVS and return a :class:`openquake.engine.JobContext` object. If the calculation is not currently running, a :exception:`JobCompletedError` is raised. :returns: :class:`openquake.engine.JobContext` object, representing an in-progress job. 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.JobContext.is_job_completed` returns ``True`` for ``job_id``. """ # pylint: disable=W0404 from openquake.engine import JobContext if JobContext.is_job_completed(job_id): raise JobCompletedError(job_id) job_ctxt = JobContext.from_kvs(job_id) if job_ctxt and job_ctxt.params: level = job_ctxt.log_level else: level = 'warn' logs.init_logs_amqp_send(level=level, job_id=job_id) return job_ctxt
def test_can_store_and_read_jobs_from_kvs(self): self.job_ctxt._log_level = 'debug' self.job_ctxt.params['debug'] = self.job_ctxt.log_level try: self.job_ctxt.to_kvs() job_from_kvs = JobContext.from_kvs(self.job_ctxt.job_id) self.assertEqual(self.job_ctxt.params, job_from_kvs.params) finally: helpers.cleanup_loggers()