diff --git a/src/DIRAC/RequestManagementSystem/Client/ReqClient.py b/src/DIRAC/RequestManagementSystem/Client/ReqClient.py index bb9f64e9d9c..7c73c81fc7f 100755 --- a/src/DIRAC/RequestManagementSystem/Client/ReqClient.py +++ b/src/DIRAC/RequestManagementSystem/Client/ReqClient.py @@ -5,6 +5,7 @@ :synopsis: implementation of client for RequestDB using DISET framework """ + import os import time import random @@ -470,6 +471,23 @@ def resetFailedRequest(self, requestID, allR=False): return self.putRequest(req) return S_OK("Not reset") + @ignoreEncodeWarning + def getBulkRequestStatus(self, requestIDs: list[int]): + """get the Status for the supplied request IDs. + + :param self: self reference + :param list requestIDs: list of job IDs (integers) + :return: S_ERROR or S_OK( { reqID1:status, requID2:status2, ... }) + """ + res = self._getRPC().getBulkRequestStatus(requestIDs) + if not res["OK"]: + return res + + # Cast the requestIDs back to int + statuses = strToIntDict(res["Value"]) + + return S_OK(statuses) + # ============= Some useful functions to be shared =========== diff --git a/src/DIRAC/RequestManagementSystem/DB/RequestDB.py b/src/DIRAC/RequestManagementSystem/DB/RequestDB.py index 5bd6b372923..978bb8bd06f 100644 --- a/src/DIRAC/RequestManagementSystem/DB/RequestDB.py +++ b/src/DIRAC/RequestManagementSystem/DB/RequestDB.py @@ -869,6 +869,16 @@ def getRequestStatus(self, requestID): session.close() return S_OK(status[0]) + def getBulkRequestStatus(self, requestIDs): + """get requests statuses for given request IDs""" + session = self.DBSession() + try: + statuses = session.query(Request.RequestID, Request._Status).filter(Request.RequestID.in_(requestIDs)).all() + status_dict = {req_id: req_status for req_id, req_status in statuses} + finally: + session.close() + return S_OK(status_dict) + def getRequestFileStatus(self, requestID, lfnList): """get status for files in request given its id diff --git a/src/DIRAC/RequestManagementSystem/Service/ReqManagerHandler.py b/src/DIRAC/RequestManagementSystem/Service/ReqManagerHandler.py index 9d51ba7a17d..ca616c17306 100755 --- a/src/DIRAC/RequestManagementSystem/Service/ReqManagerHandler.py +++ b/src/DIRAC/RequestManagementSystem/Service/ReqManagerHandler.py @@ -340,6 +340,16 @@ def export_getRequestStatus(cls, requestID): gLogger.error(f"getRequestStatus: {status['Message']}") return status + types_getBulkRequestStatus = [list] + + @classmethod + def export_getBulkRequestStatus(cls, requestIDs): + """get requests statuses given their ids""" + res = cls.__requestDB.getBulkRequestStatus(requestIDs) + if not res["OK"]: + gLogger.error(f"getRequestStatus: {res['Message']}") + return res + types_getRequestFileStatus = [int, [str, list]] @classmethod