Skip to content

Commit

Permalink
feat (RMS): getBulkRequestStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen committed Aug 12, 2024
1 parent 0cde547 commit b903955
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/DIRAC/RequestManagementSystem/Client/ReqClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:synopsis: implementation of client for RequestDB using DISET framework
"""

import os
import time
import random
Expand Down Expand Up @@ -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 ===========

Expand Down
10 changes: 10 additions & 0 deletions src/DIRAC/RequestManagementSystem/DB/RequestDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/DIRAC/RequestManagementSystem/Service/ReqManagerHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b903955

Please sign in to comment.