2055 def _update_result_status(self, condor_q_output):
2056 """
2057 In order to be slightly more efficient we pass in a previous call to condor_q to see if it can work.
2058 If it is there we update the job's status. If not we are forced to start calling condor_q and, if needed,
2059 ``condor_history``, etc.
2060
2061 Parameters:
2062 condor_q_output (dict): The JSON output of a previous call to `HTCondor.condor_q` which we can reuse to find the
2063 status of this job if it was active when that command ran.
2064 """
2065 B2DEBUG(29, f"Calling {self.job}.result._update_result_status()")
2066 jobs_info = []
2067 for job_record in condor_q_output["JOBS"]:
2068 job_id = job_record["GlobalJobId"].split("#")[1]
2069 if job_id == self.job_id:
2070 B2DEBUG(29, f"Found {self.job_id} in condor_q_output.")
2071 jobs_info.append(job_record)
2072
2073
2074 if not jobs_info:
2075 try:
2076 exit_code = self.get_exit_code_from_file()
2077 except FileNotFoundError:
2078 waiting_time = datetime.now() - self.exit_code_file_initial_time
2079 if self.time_to_wait_for_exit_code_file > waiting_time:
2080 B2ERROR(f"Exit code file for {self.job} missing and we can't wait longer. Setting exit code to 1.")
2081 exit_code = 1
2082 else:
2083 B2WARNING(f"Exit code file for {self.job} missing, will wait longer.")
2084 return
2085 if exit_code:
2086 jobs_info = [{"JobStatus": 6, "HoldReason": None}]
2087 else:
2088 jobs_info = [{"JobStatus": 4, "HoldReason": None}]
2089
2090
2091 if not jobs_info:
2092 jobs_info = HTCondor.condor_q(job_id=self.job_id, class_ads=["JobStatus", "HoldReason"])["JOBS"]
2093
2094
2095
2096 if not jobs_info:
2097 try:
2098 jobs_info = HTCondor.condor_history(job_id=self.job_id, class_ads=["JobStatus", "HoldReason"])["JOBS"]
2099 except KeyError:
2100 hold_reason = "No Reason Known"
2101
2102
2103 if not jobs_info:
2104 jobs_info = [{"JobStatus": 6, "HoldReason": None}]
2105
2106 job_info = jobs_info[0]
2107 backend_status = job_info["JobStatus"]
2108
2109 if backend_status == 5:
2110 hold_reason = job_info.get("HoldReason", None)
2111 B2WARNING(f"{self.job} on hold because of {hold_reason}. Keep waiting.")
2112 backend_status = 2
2113 try:
2114 new_job_status = self.backend_code_to_status[backend_status]
2115 except KeyError as err:
2116 raise BackendError(f"Unidentified backend status found for {self.job}: {backend_status}") from err
2117 if new_job_status != self.job.status:
2118 self.job.status = new_job_status
2119
2120 @classmethod