コード例 #1
0
def clear():
    """
    Produces timed status reports
    """
    # Clear queues at most every 24 hours to prevent filling up.
    # There is no better way to clear a multiprocessing queue other than run a loop.
    log = 'Attempting to clear activity and status queues.'
    logger.debug(log)
    MPQ_ACT.put_nowait([datetime.now().isoformat(' '), 'DEBUG', log])

    while not MPQ_STAT.empty():
        MPQ_STAT.get()
        time.sleep(0.001)

    while not MPQ_ACT.empty():
        MPQ_ACT.get()
        time.sleep(0.001)

    log = 'Activity and status queues cleared.'
    logger.info(log)
    MPQ_ACT.put_nowait([datetime.now().isoformat(' '), 'INFO', log])
コード例 #2
0
    def act_listener(self, ):
        """
        Places activity messages into websocket queue as they are received.

        mpq_record[0] = dtg
        mpq_record[1] = status
        mpq_record[2] = message
        """
        log_level = 'DEBUG'
        pid_websocket = False

        while not self.stat_list:

            # All JanusESS status information enters this point
            if not MPQ_ACT_CMD.empty():
                mpq_record = MPQ_ACT_CMD.get()
                if mpq_record[0] == 'log_level':
                    if log_level != mpq_record[1]:
                        log_level = mpq_record[1]

                if mpq_record[0] == 'websocket':
                    if pid_websocket != mpq_record[1]:
                        pid_websocket = mpq_record[1]

            # Only retrieve MPQ_ACT if websocket handler is functioning.
            if pid_websocket:
                if not MPQ_ACT.empty():
                    mpq_record = MPQ_ACT.get()

                    # Compare activity logging level with activity statement, if activity
                    # statement has higher level, place it onto queue
                    if LOG_LVL[mpq_record[1]] >= LOG_LVL[log_level]:
                        try:
                            MPQ_WS.put([
                                'activity', mpq_record[0][:19] + ' ' +
                                mpq_record[1] + ': ' + mpq_record[2]
                            ])

                        except queue.Full:
                            log = 'Can not place item in activity queue, malformed record or queue is full.'
                            logger.exception(log)

            time.sleep(0.02)