def show_bulk_discovery_status(params) -> Response: """Show the status of a bulk discovery job""" job_id = params["job_id"] job = BulkDiscoveryBackgroundJob() if job.get_job_id() != job_id: raise ProblemException( status=404, title=f"Background job {job_id} not found.", ) return _serve_background_job(job)
def _serve_background_job(job: BulkDiscoveryBackgroundJob) -> Response: job_id = job.get_job_id() status_details = bulk_discovery_job_status(job) return constructors.serve_json( constructors.domain_object( domain_type="discovery_run", identifier=job_id, title= f"Background job {job_id} {'is active' if status_details['is_active'] else 'is finished'}", extensions={ "active": status_details["is_active"], "state": status_details["job_state"], "logs": status_details["logs"], }, deletable=False, editable=False, ))