当前位置: 首页>>代码示例>>Python>>正文


Python RequestContainer.getJobID方法代码示例

本文整理汇总了Python中DIRAC.RequestManagementSystem.Client.RequestContainer.RequestContainer.getJobID方法的典型用法代码示例。如果您正苦于以下问题:Python RequestContainer.getJobID方法的具体用法?Python RequestContainer.getJobID怎么用?Python RequestContainer.getJobID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DIRAC.RequestManagementSystem.Client.RequestContainer.RequestContainer的用法示例。


在下文中一共展示了RequestContainer.getJobID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getRequest

# 需要导入模块: from DIRAC.RequestManagementSystem.Client.RequestContainer import RequestContainer [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.RequestContainer.RequestContainer import getJobID [as 别名]
    def getRequest(self, requestType):
        """ Obtain a request from the database of a :requestType: type
    
    :param self: self reference
    :param str requestType: request type
    """
        self.log.info("getRequest: Attempting to get %s type request." % requestType)
        try:
            # Determine the request name to be obtained
            candidateRequests = []
            reqDir = os.path.join(self.root, requestType, "Waiting")
            self.getIdLock.acquire()
            if os.path.exists(reqDir):
                candidateRequests = [
                    os.path.basename(requestFile)
                    for requestFile in sorted(
                        filter(
                            os.path.isfile, [os.path.join(reqDir, requestName) for requestName in os.listdir(reqDir)]
                        ),
                        key=os.path.getctime,
                    )
                ]
            if not len(candidateRequests) > 0:
                self.getIdLock.release()
                self.log.info("getRequest: No request of type %s found." % requestType)
                return S_OK()

            # Select a request
            if requestType not in self.lastRequest:
                self.lastRequest[requestType] = ("", 0)
            lastRequest, lastRequestIndex = self.lastRequest[requestType]
            res = self.__selectRequestCursor(candidateRequests, lastRequest, lastRequestIndex)
            if not res["OK"]:
                self.getIdLock.release()
                errStr = "getRequest: Failed to get request cursor."
                self.log.error(errStr, res["Message"])
                return S_ERROR(errStr)
            selectedRequestName, selectedRequestIndex = res["Value"]

            # Obtain the string for the selected request
            res = self.__getRequestString(selectedRequestName)
            if not res["OK"]:
                self.getIdLock.release()
                errStr = "getRequest: Failed to get request string for %s." % selectedRequestName
                self.log.error(errStr, res["Message"])
                return S_ERROR(errStr)
            selectedRequestString = res["Value"]

            # Set the request status to assigned
            res = self.setRequestStatus(selectedRequestName, "Assigned")
            if not res["OK"]:
                self.getIdLock.release()
                errStr = "getRequest: Failed to set %s status to 'Assigned'." % selectedRequestName
                self.log.error(errStr, res["Message"])
                return S_ERROR(errStr)

            # Update the request cursor and return the selected request
            self.lastRequest[requestType] = (selectedRequestName, selectedRequestIndex)
            self.getIdLock.release()
            self.log.info("getRequest: Successfully obtained %s request." % selectedRequestName)
            oRequest = RequestContainer(request=selectedRequestString)
            jobID = oRequest.getJobID()
            jobID = jobID["Value"] if jobID["OK"] and jobID["Value"] else 0
            try:
                jobID = int(jobID)
            except (TypeError, ValueError), error:
                self.log.error("getRequest: could not get JobID from Request, setting it to 0: %s" % str(error))
                jobID = 0
            return S_OK({"RequestString": selectedRequestString, "RequestName": selectedRequestName, "JobID": jobID})
开发者ID:hanyl,项目名称:DIRAC,代码行数:71,代码来源:RequestDBFile.py

示例2: setRequest

# 需要导入模块: from DIRAC.RequestManagementSystem.Client.RequestContainer import RequestContainer [as 别名]
# 或者: from DIRAC.RequestManagementSystem.Client.RequestContainer.RequestContainer import getJobID [as 别名]
 def setRequest( self, requestName, requestString ):
   """ insert request :requestName: to teh db
   
   :param str requestName: Requests.RequestName
   :param str requestString: xml-serialised request
   """
   request = RequestContainer( init = True, request = requestString )
   requestTypes = request.getSubRequestTypes()['Value']
   failed = False
   res = self._getRequestID( requestName )
   if not res['OK']:
     # we have a special case here: if request already exists, we override it if it
     # comes from a DIRAC job. This is identified by having a meaningful JobID in
     # the request
     if res['Message'].find( 'Duplicate' ) != -1:
       # Duplicate request
       jobID = request.getJobID()['Value']
       if jobID == "Unknown":
         return res
       try:
         jobID = int( jobID )
       except:
         return res
       if jobID > 0:
         # Remove the existing request
         result = self._deleteRequest( requestName )
         if not result['OK']:
           message = res['Message']
           return S_ERROR( 'Failed to set request: ' + message + ' can not override' )
         res = self._getRequestID( requestName )
         if not res['OK']:
           return res
     else:
       return res
   requestID = res['Value']
   subRequestIDs = {}
   res = self.__setRequestAttributes( requestID, request )
   if res['OK']:
     for requestType in requestTypes:
       res = request.getNumSubRequests( requestType )
       numRequests = res['Value']
       for ind in range( numRequests ):
         res = self._getSubRequestID( requestID, requestType )
         if res['OK']:
           subRequestID = res['Value']
           res = self.__setSubRequestAttributes( requestID, ind, requestType, subRequestID, request )
           if res['OK']:
             subRequestIDs[subRequestID] = res['Value']
             res = self.__setSubRequestFiles( ind, requestType, subRequestID, request )
             if res['OK']:
               res = self.__setSubRequestDatasets( ind, requestType, subRequestID, request )
               if not res['OK']:
                 failed = True
                 message = res['Message']
             else:
               failed = True
               message = res['Message']
           else:
             failed = True
             message = res['Message']
         else:
           failed = True
           message = res['Message']
   else:
     failed = True
     message = res['Message']
   for subRequestID, status in subRequestIDs.items():
     if not status:
       status = "Waiting"
     res = self._setSubRequestAttribute( requestID, subRequestID, 'Status', status )
     if not res['OK']:
       failed = True
       message = res['Message']
   res = self._setRequestAttribute( requestID, 'Status', 'Waiting' )
   if not res['OK']:
     failed = True
     message = res['Message']
   if failed:
     res = self._deleteRequest( requestName )
     return S_ERROR( 'Failed to set request: ' + message )
   else:
     return S_OK( requestID )
开发者ID:sbel,项目名称:bes3-jinr,代码行数:84,代码来源:RequestDBMySQL.py


注:本文中的DIRAC.RequestManagementSystem.Client.RequestContainer.RequestContainer.getJobID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。