status_enum.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from enum import Enum
  2. class TestTaskStatus(Enum):
  3. NOT_STARTED = 0
  4. IN_PROGRESS = 1
  5. COMPLETED = 2
  6. CANCELLED = 3
  7. FAILED = 4
  8. CREATING = 5
  9. CREATED_FAIL = 6
  10. @property
  11. def description(self):
  12. descriptions = {
  13. self.NOT_STARTED: "未开始",
  14. self.IN_PROGRESS: "进行中",
  15. self.COMPLETED: "已完成",
  16. self.CANCELLED: "已取消",
  17. self.FAILED: "已失败",
  18. self.CREATING: "生成任务中",
  19. self.CREATED_FAIL:"生成任务失败"
  20. }
  21. return descriptions.get(self)
  22. # 使用示例
  23. def get_test_task_status_desc(status_code):
  24. try:
  25. status = TestTaskStatus(status_code)
  26. return status.description
  27. except ValueError:
  28. return f"未知状态: {status_code}"
  29. class TestTaskConversationsStatus(Enum):
  30. """任务状态枚举类"""
  31. PENDING = 0 # 待执行
  32. RUNNING = 1 # 执行中
  33. SUCCESS = 2 # 执行成功
  34. FAILED = 3 # 执行失败
  35. CANCELLED = 4 # 已取消
  36. @property
  37. def description(self):
  38. descriptions = {
  39. self.PENDING: "待执行",
  40. self.RUNNING: "执行中",
  41. self.SUCCESS: "执行成功",
  42. self.FAILED: "执行失败",
  43. self.CANCELLED: "已取消"
  44. }
  45. return descriptions.get(self)
  46. # 使用示例
  47. def get_test_task_conversations_status_desc(status_code):
  48. try:
  49. status = TestTaskConversationsStatus(status_code)
  50. return status.description
  51. except ValueError:
  52. return f"未知状态: {status_code}"