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 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 test_is_job_completed(self): job_id = engine._job_from_file(helpers.get_data_path(CONFIG_FILE), "db").job_id row = models.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(JobContext.is_job_completed(job_id), is_completed)
def test_is_job_completed(self): job_id = engine._job_from_file( helpers.get_data_path(CONFIG_FILE), 'db').job_id row = models.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( JobContext.is_job_completed(job_id), is_completed)