models.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (C) 2025 AIDC-AI
  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. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. """
  13. Task data models
  14. """
  15. from datetime import datetime
  16. from enum import Enum
  17. from typing import Any, Optional
  18. from pydantic import BaseModel, Field
  19. class TaskStatus(str, Enum):
  20. """Task status"""
  21. PENDING = "pending"
  22. RUNNING = "running"
  23. COMPLETED = "completed"
  24. FAILED = "failed"
  25. CANCELLED = "cancelled"
  26. class TaskType(str, Enum):
  27. """Task type"""
  28. VIDEO_GENERATION = "video_generation"
  29. class TaskProgress(BaseModel):
  30. """Task progress information"""
  31. current: int = 0
  32. total: int = 0
  33. percentage: float = 0.0
  34. message: str = ""
  35. class Task(BaseModel):
  36. """Task model"""
  37. task_id: str
  38. task_type: TaskType
  39. status: TaskStatus = TaskStatus.PENDING
  40. # Progress tracking
  41. progress: Optional[TaskProgress] = None
  42. # Result
  43. result: Optional[Any] = None
  44. error: Optional[str] = None
  45. # Metadata
  46. created_at: datetime = Field(default_factory=datetime.now)
  47. started_at: Optional[datetime] = None
  48. completed_at: Optional[datetime] = None
  49. # Request parameters (for reference)
  50. request_params: Optional[dict] = None
  51. class Config:
  52. json_encoders = {
  53. datetime: lambda v: v.isoformat()
  54. }