Exemplo n.º 1
0
    def processRecords(self):
        """
    It consumes all messaged from the MQ (these are failover messages). In case of failure, the messages
    will be inserted to the MQ again.
    """
        retVal = monitoringDB.pingDB(
        )  # if the db is not accessible, the records will be not processed from MQ
        if retVal['OK']:
            if not retVal['Value']:  # false if we can not connect to the db
                return retVal
        else:
            return retVal

        result = createConsumer("Monitoring::Queue::%s" %
                                self.__monitoringType)
        if not result['OK']:
            gLogger.error("Fail to create Consumer: %s" % result['Message'])
            return S_ERROR("Fail to create Consumer: %s" % result['Message'])
        else:
            mqConsumer = result['Value']

        result = S_OK()
        failedToProcess = []
        while result['OK']:
            # we consume all messages from the consumer internal queue.
            result = mqConsumer.get()
            if result['OK']:
                records = json.loads(result['Value'])
                retVal = monitoringDB.put(list(records), self.__monitoringType)
                if not retVal['OK']:
                    failedToProcess.append(records)

        mqConsumer.close(
        )  # make sure that we will not process any more messages.
        # the db is not available and we publish again the data to MQ
        for records in failedToProcess:
            res = self.publishRecords(records)
            if not res['OK']:
                return res
        return S_OK()
Exemplo n.º 2
0
  def processRecords(self):
    """
    It consumes all messaged from the MQ (these are failover messages). In case of failure, the messages
    will be inserted to the MQ again.
    """
    retVal = monitoringDB.pingDB()  # if the db is not accessible, the records will be not processed from MQ
    if retVal['OK']:
      if not retVal['Value']:  # false if we can not connect to the db
        return retVal
    else:
      return retVal

    result = createConsumer("Monitoring::Queue::%s" % self.__failoverQueueName)
    if not result['OK']:
      gLogger.error("Fail to create Consumer: %s" % result['Message'])
      return S_ERROR("Fail to create Consumer: %s" % result['Message'])
    else:
      mqConsumer = result['Value']

    result = S_OK()
    failedToProcess = []
    while result['OK']:
      # we consume all messages from the consumer internal queue.
      result = mqConsumer.get()
      if result['OK']:
        records = json.loads(result['Value'])
        retVal = monitoringDB.put(list(records), self.__monitoringType)
        if not retVal['OK']:
          failedToProcess.append(records)

    mqConsumer.close()  # make sure that we will not process any more messages.
    # the db is not available and we publish again the data to MQ
    for records in failedToProcess:
      res = self.publishRecords(records)
      if not res['OK']:
        return res
    return S_OK()