Beispiel #1
0
    def worker_will_run(self):
        try:
            if self._MQPublisher:
                self._MQPublisher.stop()

            self._MQPublisher = OMQSAsyncPublisher(exchange_name='omqs.exchange.event',
                                                   queue_name='omqs.queue.event',
                                                   exchange_durable=True,
                                                   queue_durable=True,
                                                   confirm=False)
            if self._MQPublisher:
                self._MQthread = threading.Thread(target=self._MQPublisher.run, name='PublishingThread')
                self._MQthread.start()

                while not self._MQPublisher.is_ready():
                    time.sleep(0.1)

                self._logger.info('[%s][%d] ready to run!', self.name, self.pid)
            else:
                raise InvalidPublisherError

        except Exception, e:
            self._logger.error('[%s][%d] error: %s. Stopping the publisher', self.name, self.pid, str(e))
            if self._MQPublisher:
                self._MQPublisher.stop()
                self._MQPublisher = None
Beispiel #2
0
class EventMsgWorker(MsgWorker):

    EVENT_KEY = 'omqs.key.event'

    def __init__(self, q, name='EventMsgWorker'):
        super(EventMsgWorker, self).__init__(q, name)

        self._MQPublisher = None
        self._MQthread = None

        manager = OMQSLogManager(name=__name__, file_name=name)
        self._logger = manager.logger


    def worker_will_run(self):
        try:
            if self._MQPublisher:
                self._MQPublisher.stop()

            self._MQPublisher = OMQSAsyncPublisher(exchange_name='omqs.exchange.event',
                                                   queue_name='omqs.queue.event',
                                                   exchange_durable=True,
                                                   queue_durable=True,
                                                   confirm=False)
            if self._MQPublisher:
                self._MQthread = threading.Thread(target=self._MQPublisher.run, name='PublishingThread')
                self._MQthread.start()

                while not self._MQPublisher.is_ready():
                    time.sleep(0.1)

                self._logger.info('[%s][%d] ready to run!', self.name, self.pid)
            else:
                raise InvalidPublisherError

        except Exception, e:
            self._logger.error('[%s][%d] error: %s. Stopping the publisher', self.name, self.pid, str(e))
            if self._MQPublisher:
                self._MQPublisher.stop()
                self._MQPublisher = None