context.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright 2021 EMQ Technologies Co., Ltd.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """context.py: Context defines context information available during
  15. # processing of a request.
  16. """
  17. import logging
  18. from abc import abstractmethod
  19. class Context(object):
  20. """Interface defining information available at process time"""
  21. @abstractmethod
  22. def get_rule_id(self) -> str:
  23. """Return the ruleId of the current stream processing graph"""
  24. pass
  25. @abstractmethod
  26. def get_op_id(self) -> str:
  27. """Return the operation id"""
  28. pass
  29. @abstractmethod
  30. def get_instance_id(self) -> int:
  31. """Return the instance id"""
  32. pass
  33. @abstractmethod
  34. def get_logger(self) -> logging:
  35. """Returns the logger object that can be used to do logging"""
  36. pass
  37. @abstractmethod
  38. def emit(self, message: dict, meta: dict):
  39. """Emit the tuple to the stream"""
  40. pass
  41. @abstractmethod
  42. def emit_error(self, error: str):
  43. """Emit error to the stream"""
  44. pass