event_notifier.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from __future__ import absolute_import
  2. import logging
  3. log = logging.getLogger(__name__)
  4. class AbstractBaseEventNotifier(object):
  5. """ Abstract base EventNotifier that allows receiving notifications for
  6. different events with default implementations.
  7. See :class:`hystrix.strategy.plugins.Plugin` or the Hystrix GitHub Wiki
  8. for information on `configuring plugins
  9. <https://github.com/Netflix/Hystrix/wiki/Plugins>`_.
  10. .. note::
  11. Note on thread-safety and performance
  12. A single implementation of this class will be used globally so methods
  13. on this class will be invoked concurrently from multiple threads so
  14. all functionality must be thread-safe.
  15. Methods are also invoked synchronously and will add to execution time
  16. of the commands so all behavior should be fast. If anything
  17. time-consuming is to be done it should be spawned asynchronously
  18. onto separate worker threads.
  19. """
  20. def mark_event(self, event_type, command_name):
  21. """ Called for every event fired.
  22. This is the default Implementation and does nothing
  23. Args:
  24. event_type: A :class:hystrix.event_type.EventType` occurred
  25. during execution.
  26. command_key: Command instance name.
  27. """
  28. # Do nothing
  29. pass
  30. def mark_command_execution(self, command_name, isolation_strategy, duration, events_type):
  31. """ Called after a command is executed using thread isolation.
  32. Will not get called if a command is rejected, short-circuited etc.
  33. This is the default Implementation and does nothing
  34. Args:
  35. command_key: Command instance name.
  36. isolation_strategy: :class:`ExecutionIsolationStrategy` the
  37. isolation strategy used by the command when executed
  38. duration: Time in milliseconds of executing
  39. :meth:`hystrix.command.Command.run()` method.
  40. events_type: A list of :class:hystrix.event_type.EventType` of events
  41. occurred during execution.
  42. """
  43. # Do nothing
  44. pass