Пример #1
0
    def reportOnQueues(self):

        if self.reportCollectionRef:
            priorities = ['H', 'M', 'L']
            qDict = {'qCheckTime': datetime.now()}
            for priority in priorities:
                qArray = []

                if priority == 'H':
                    theQ = self.sqlBHandler.sqlQname_H
                elif priority == 'M':
                    theQ = self.sqlBHandler.sqlQname_M
                elif priority == 'L':
                    theQ = self.sqlBHandler.sqlQname_L

                qlen = self.getQLens(priority)
                qlenKey = f'{priority}__len'
                qcontentKey = f'{priority}_content'

                qDict[qlenKey] = qlen

                qcontents = self.sqlBHandler.redis_client.lrange(theQ, -10, -1)
                for element in qcontents:
                    elementParsed = json.loads(element,
                                               cls=mu.RoundTripDecoder)
                    qArray.append(elementParsed)

                qDict[qcontentKey] = qArray
            docUid = mu.makeAscendingUid()

            self.reportCollectionRef.document(docUid).set(qDict)
Пример #2
0
    def persistErrorDetailInFB(self, exception, attempt, willBeRetried=True):
        lst = dir(exception)
        dict_ = {
            'attempt': attempt,
            'createdAt': datetime.now(),
            'willBeRetried': willBeRetried,
            '_type': str(type(exception))
        }
        if 'orig' in lst:
            try:
                dict_['orig_args'] = exception.orig.args[0]
            except:
                dict_['orig_args_M'] = 'Unable to get this'
        if 'args' in lst:
            dict_['args'] = str(exception.args)
        if 'code' in lst:
            dict_['code'] = exception.code
        if 'statement' in lst:
            dict_['statement'] = exception.statement
        if 'params' in lst and exception.params:
            dict_['params'] = list(exception.params)
        if 'connection_invalidated' in lst:
            dict_['connection_invalidated'] = exception.connection_invalidated
        if 'detail' in lst:
            dict_['detail'] = exception.detail

        if self.fb_db:
            docuid = mu.makeAscendingUid()
            destDoc = self.fb_db.collection('logging/sqlQ/errors').document(
                docuid)
            print(
                f'Error record will be written to Firebase as docUid={docuid}: {dict_}'
            )
            destDoc.set(dict_)