decorator.py 692 B

123456789101112131415161718192021
  1. import functools
  2. from compose.metrics.client import MetricsCommand
  3. from compose.metrics.client import Status
  4. class metrics:
  5. def __init__(self, command_name=None):
  6. self.command_name = command_name
  7. def __call__(self, fn):
  8. @functools.wraps(fn,
  9. assigned=functools.WRAPPER_ASSIGNMENTS,
  10. updated=functools.WRAPPER_UPDATES)
  11. def wrapper(*args, **kwargs):
  12. if not self.command_name:
  13. self.command_name = fn.__name__
  14. result = fn(*args, **kwargs)
  15. MetricsCommand(self.command_name, status=Status.SUCCESS).send_metrics()
  16. return result
  17. return wrapper