def send(self, type, blind=False, utcoffset=utcoffset, retry=False, retry_policy=None, Event=Event, **fields): """Send event. :param type: Event type name, with group separated by dash (`-`). :keyword retry: Retry in the event of connection failure. :keyword retry_policy: Dict of custom retry policy, see :meth:`~kombu.Connection.ensure`. :keyword blind: Don't set logical clock value (also do not forward the internal logical clock). :keyword Event: Event type used to create event, defaults to :func:`Event`. :keyword utcoffset: Function returning the current utcoffset in hours. :keyword \*\*fields: Event fields, must be json serializable. """ if self.enabled: groups, group = self.groups, group_from(type) if groups and group not in groups: return if group in self.buffer_group: clock = self.clock.forward() event = Event(type, hostname=self.hostname, utcoffset=utcoffset(), pid=self.pid, clock=clock, **fields) buf = self._group_buffer[group] buf.append(event) if len(buf) >= self.buffer_limit: self.flush() elif self.on_send_buffered: self.on_send_buffered() else: return self.publish(type, fields, self.producer, blind=blind, Event=Event, retry=retry, retry_policy=retry_policy)
def publish(self, type, fields, producer, blind=False, Event=Event, **kwargs): """Publish event using a custom :class:`~kombu.Producer` instance. Arguments: type (str): Event type name, with group separated by dash (`-`). fields: Dictionary of event fields, must be json serializable. producer (kombu.Producer): Producer instance to use: only the ``publish`` method will be called. retry (bool): Retry in the event of connection failure. retry_policy (Mapping): Map of custom retry policy options. See :meth:`~kombu.Connection.ensure`. blind (bool): Don't set logical clock value (also don't forward the internal logical clock). Event (Callable): Event type used to create event. Defaults to :func:`Event`. utcoffset (Callable): Function returning the current utc offset in hours. """ clock = None if blind else self.clock.forward() event = Event(type, hostname=self.hostname, utcoffset=utcoffset(), pid=self.pid, clock=clock, **fields) with self.mutex: return self._publish(event, producer, routing_key=type.replace('-', '.'), **kwargs)
def publish(self, type, fields, producer, blind=False, Event=Event, **kwargs): """Publish event using a custom :class:`~kombu.Producer` instance. :param type: Event type name, with group separated by dash (`-`). :param fields: Dictionary of event fields, must be json serializable. :param producer: :class:`~kombu.Producer` instance to use, only the ``publish`` method will be called. :keyword retry: Retry in the event of connection failure. :keyword retry_policy: Dict of custom retry policy, see :meth:`~kombu.Connection.ensure`. :keyword blind: Don't set logical clock value (also do not forward the internal logical clock). :keyword Event: Event type used to create event, defaults to :func:`Event`. :keyword utcoffset: Function returning the current utcoffset in hours. """ clock = None if blind else self.clock.forward() event = Event(type, hostname=self.hostname, utcoffset=utcoffset(), pid=self.pid, clock=clock, **fields) with self.mutex: return self._publish(event, producer, routing_key=type.replace('-', '.'), **kwargs)
def send(self, type, utcoffset=utcoffset, blind=False, Event=Event, **fields): """Send event. :param type: Kind of event. :keyword utcoffset: Function returning the current utcoffset in hours. :keyword blind: Do not send clock value :keyword \*\*fields: Event arguments. """ if self.enabled: groups = self.groups if groups and group_from(type) not in groups: return clock = None if blind else self.clock.forward() with self.mutex: event = Event(type, hostname=self.hostname, clock=clock, utcoffset=utcoffset(), pid=self.pid, **fields) try: self.publisher.publish(event, routing_key=type.replace('-', '.'), headers=self.headers) except Exception as exc: if not self.buffer_while_offline: raise self._outbound_buffer.append((type, fields, exc))
def send(self, type, blind=False, utcoffset=utcoffset, retry=False, retry_policy=None, Event=Event, **fields): """Send event. Arguments: type (str): Event type name, with group separated by dash (`-`). retry (bool): Retry in the event of connection failure. retry_policy (Mapping): Map of custom retry policy options. See :meth:`~kombu.Connection.ensure`. blind (bool): Don't set logical clock value (also do not forward the internal logical clock). Event (Callable): Event type used to create event, defaults to :func:`Event`. utcoffset (Callable): unction returning the current utc offset in hours. **fields (Any): Event fields -- must be json serializable. """ if self.enabled: groups, group = self.groups, group_from(type) if groups and group not in groups: return if group in self.buffer_group: clock = self.clock.forward() event = Event(type, hostname=self.hostname, utcoffset=utcoffset(), pid=self.pid, clock=clock, **fields) buf = self._group_buffer[group] buf.append(event) if len(buf) >= self.buffer_limit: self.flush() elif self.on_send_buffered: self.on_send_buffered() else: return self.publish( type, fields, self.producer, blind=blind, Event=Event, retry=retry, retry_policy=retry_policy )
def send(self, type, blind=False, utcoffset=utcoffset, retry=False, retry_policy=None, Event=Event, **fields): """Send event. Arguments: type (str): Event type name, with group separated by dash (`-`). retry (bool): Retry in the event of connection failure. retry_policy (Mapping): Map of custom retry policy options. See :meth:`~kombu.Connection.ensure`. blind (bool): Don't set logical clock value (also don't forward the internal logical clock). Event (Callable): Event type used to create event, defaults to :func:`Event`. utcoffset (Callable): unction returning the current utc offset in hours. **fields (Any): Event fields -- must be json serializable. """ if self.enabled: groups, group = self.groups, group_from(type) if groups and group not in groups: return if group in self.buffer_group: clock = self.clock.forward() event = Event(type, hostname=self.hostname, utcoffset=utcoffset(), pid=self.pid, clock=clock, **fields) buf = self._group_buffer[group] buf.append(event) if len(buf) >= self.buffer_limit: self.flush() elif self.on_send_buffered: self.on_send_buffered() else: return self.publish(type, fields, self.producer, blind=blind, Event=Event, retry=retry, retry_policy=retry_policy)
def publish(self, type, fields, producer, retry=False, retry_policy=None, blind=False, utcoffset=utcoffset, Event=Event): with self.mutex: clock = None if blind else self.clock.forward() event = Event(type, hostname=self.hostname, utcoffset=utcoffset(), pid=self.pid, clock=clock, **fields) exchange = self.exchange producer.publish( event, routing_key=type.replace('-', '.'), exchange=exchange.name, retry=retry, retry_policy=retry_policy, declare=[exchange], serializer=self.serializer, headers=self.headers, )
def publish(self, type, fields, producer, blind=False, Event=Event, **kwargs): """Publish event using a custom :class:`~kombu.Producer` instance. Arguments: type (str): Event type name, with group separated by dash (`-`). fields: Dictionary of event fields, must be json serializable. producer (kombu.Producer): Producer instance to use: only the ``publish`` method will be called. retry (bool): Retry in the event of connection failure. retry_policy (Mapping): Map of custom retry policy options. See :meth:`~kombu.Connection.ensure`. blind (bool): Don't set logical clock value (also don't forward the internal logical clock). Event (Callable): Event type used to create event. Defaults to :func:`Event`. utcoffset (Callable): Function returning the current utc offset in hours. """ clock = None if blind else self.clock.forward() event = Event(type, hostname=self.hostname, utcoffset=utcoffset(), pid=self.pid, clock=clock, **fields) with self.mutex: return self._publish(event, producer, routing_key=type.replace('-', '.'), **kwargs)
def send(self, type, utcoffset=utcoffset, blind=False, Event=Event, **fields): """Send event. :param type: Kind of event. :keyword utcoffset: Function returning the current utcoffset in hours. :keyword blind: Do not send clock value :keyword \*\*fields: Event arguments. """ if self.enabled: groups = self.groups if groups and group_from(type) not in groups: return clock = None if blind else self.clock.forward() with self.mutex: event = Event(type, hostname=self.hostname, clock=clock, utcoffset=utcoffset(), pid=self.pid, **fields) try: self.publisher.publish(event, routing_key=type.replace('-', '.'), headers=self.headers) except Exception as exc: if not self.buffer_while_offline: raise self._outbound_buffer.append((type, fields, exc))
def test_utcoffset(self): with patch('celery.utils.timeutils._time') as _time: _time.daylight = True self.assertIsNotNone(utcoffset()) _time.daylight = False self.assertIsNotNone(utcoffset())
def test_utcoffset(self): with patch('celery.utils.timeutils._time') as _time: _time.daylight = True self.assertIsNotNone(utcoffset()) _time.daylight = False self.assertIsNotNone(utcoffset())