Ejemplo n.º 1
0
 def release(self):
     try:
         self.unlock()
         self.lockfile.close()
         LOG.debug('Released file lock "%s"', self.fname)
     except IOError:
         LOG.exception(_LE("Could not release the acquired lock `%s`"),
                       self.fname)
Ejemplo n.º 2
0
 def release(self):
     try:
         self.unlock()
         self.lockfile.close()
         LOG.debug('Released file lock "%s"', self.fname)
     except IOError:
         LOG.exception(_LE("Could not release the acquired lock `%s`"),
                       self.fname)
Ejemplo n.º 3
0
    def _publish(self, payload):
        """Publishes a payload to the passed exchange. If it encounters a
        failure, will store the payload for later.

        :param Payload payload: The payload to send.
        """
        LOG.debug(
            _("Sending message to %(name)s [%(topic)s]") % {
                'name': self._exchange_name,
                'topic': payload.topic
            })

        # First check, are we closing?
        if self._closing:
            LOG.warning(_LW("Cannot send message, publisher is closing."))
            if payload not in self._pending:
                self._pending.append(payload)
            return

        # Second check, are we open?
        if not self._open:
            LOG.debug(_("Cannot send message, publisher is connecting."))
            if payload not in self._pending:
                self._pending.append(payload)
            self._reconnect()
            return

        # Third check, are we in a sane state? This should never happen,
        # but just in case...
        if not self._connection or not self._channel:
            LOG.error(
                _LE("Cannot send message, publisher is "
                    "an unexpected state."))
            if payload not in self._pending:
                self._pending.append(payload)
            self._reconnect()
            return

        # Try to send a message. If we fail, schedule a reconnect and store
        # the message.
        try:
            self._channel.basic_publish(
                self._exchange_name, payload.topic,
                json.dumps(payload.payload, ensure_ascii=False),
                self._properties)
            if payload in self._pending:
                self._pending.remove(payload)
            return True
        except ConnectionClosed as cc:
            LOG.warning(_LW("Attempted to send message on closed connection."))
            LOG.debug(cc)
            self._open = False
            if payload not in self._pending:
                self._pending.append(payload)
            self._reconnect()
            return False
Ejemplo n.º 4
0
    def _publish(self, payload):
        """Publishes a payload to the passed exchange. If it encounters a
        failure, will store the payload for later.

        :param Payload payload: The payload to send.
        """
        LOG.debug(_("Sending message to %(name)s [%(topic)s]") %
                  {'name': self._exchange_name, 'topic': payload.topic})

        # First check, are we closing?
        if self._closing:
            LOG.warning(_LW("Cannot send message, publisher is closing."))
            if payload not in self._pending:
                self._pending.append(payload)
            return

        # Second check, are we open?
        if not self._open:
            LOG.debug(_("Cannot send message, publisher is connecting."))
            if payload not in self._pending:
                self._pending.append(payload)
            self._reconnect()
            return

        # Third check, are we in a sane state? This should never happen,
        # but just in case...
        if not self._connection or not self._channel:
            LOG.error(_LE("Cannot send message, publisher is "
                          "an unexpected state."))
            if payload not in self._pending:
                self._pending.append(payload)
            self._reconnect()
            return

        # Try to send a message. If we fail, schedule a reconnect and store
        # the message.
        try:
            self._channel.basic_publish(self._exchange_name,
                                        payload.topic,
                                        json.dumps(payload.payload,
                                                   ensure_ascii=False),
                                        self._properties)
            if payload in self._pending:
                self._pending.remove(payload)
            return True
        except ConnectionClosed as cc:
            LOG.warning(_LW("Attempted to send message on closed connection."))
            LOG.debug(cc)
            self._open = False
            if payload not in self._pending:
                self._pending.append(payload)
            self._reconnect()
            return False
Ejemplo n.º 5
0
def load_preferences(ext, defaults):
    """Load all plugin default preferences into our cache.

    :param ext: The extension that's handling this event.
    :param defaults: The current dict of default preferences.
    """

    plugin_defaults = ext.obj.get_default_preferences()

    for key in plugin_defaults:
        if key in defaults:
            # Let's not error out here.
            LOG.error(_LE("Duplicate preference key %s found.") % (key,))
        else:
            defaults[key] = plugin_defaults[key]