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