base.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. class AbstractSession:
  2. """
  3. 由Task在当前Session上下文中调用:
  4. get_current_session
  5. get_current_task_id
  6. send_task_message
  7. next_client_event
  8. on_task_exception
  9. 由Backend调用:
  10. send_client_event
  11. get_task_messages
  12. Task和Backend都可调用:
  13. close
  14. closed
  15. .. note::
  16. 后端Backend在相应on_session_close时关闭连接时,需要保证会话内的所有消息都传送到了客户端
  17. """
  18. @staticmethod
  19. def get_current_session() -> "AbstractSession":
  20. raise NotImplementedError
  21. @staticmethod
  22. def get_current_task_id():
  23. raise NotImplementedError
  24. def __init__(self, target, on_task_message=None, on_session_close=None, **kwargs):
  25. raise NotImplementedError
  26. def send_task_message(self, message):
  27. raise NotImplementedError
  28. def next_client_event(self):
  29. raise NotImplementedError
  30. def send_client_event(self, event):
  31. raise NotImplementedError
  32. def get_task_messages(self):
  33. raise NotImplementedError
  34. def close(self):
  35. raise NotImplementedError
  36. def closed(self):
  37. raise NotImplementedError
  38. def on_task_exception(self):
  39. raise NotImplementedError