NoMessageInterface.py 1.18 KB
Newer Older
1 2 3 4 5
import logging
import time
import threading
logger = logging.getLogger(__name__)

6
from balsam.common import MessageInterface
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

class NoMessageInterface(MessageInterface.MessageInterface):

    def __init__(self, settings):
        self.alive = True
        self.thread = None

    def setup_send(self):
        pass
    
    def setup_receive(self, consume_msg=None):
        self.thread = threading.Thread(target=self._fake_ioloop)
    
    def send_msg(self, message_body):
        pass

    def receive_msg(self):
        pass

    def start_receive_loop(self):
        try:
            logger.debug('starting dummy receiver ioloop')
            self.thread.start()
            self.thread.join()
        except Exception:
            logger.exception('failed to start dummy receiver ioloop')
    
    def stop_receive_loop(self):
        self.alive = False
        self.thread.join()

    def close(self):
        pass
    
    def _fake_ioloop(self):
        logger.debug('Thread: inside fake_ioloop')
        try:
            while self.alive:
                logger.debug('  Thread: Idling Receiver')
                time.sleep(15)
        except Exception:
            logger.debug('The ioloop failed')