| 120 | |
| 121 | |
| 122 | class Task(Base): |
| 123 | __tablename__ = "tasks" |
| 124 | |
| 125 | # Identifiers and status |
| 126 | id = Column(Integer, primary_key=True) |
| 127 | status = Column(String, index=True) |
| 128 | |
| 129 | sort_id = Column(Integer, index=True) # Private sort id |
| 130 | |
| 131 | # Task details |
| 132 | task_name = Column(String, index=True) |
| 133 | scraper_name = Column(String, index=True) |
| 134 | scraper_type = Column(String, index=True) |
| 135 | is_all_task = Column(Boolean, index=True) |
| 136 | is_sync = Column(Boolean, index=True) # Indexed column with default value False |
| 137 | |
| 138 | # Parent task relationship (optional) |
| 139 | parent_task_id = Column(Integer, ForeignKey("tasks.id"), nullable=True) |
| 140 | |
| 141 | started_at = Column(DateTime, nullable=True) |
| 142 | finished_at = Column(DateTime, nullable=True) |
| 143 | |
| 144 | # Data fields |
| 145 | data = Column(JSON) # JSON field for storing task data |
| 146 | meta_data = Column(JSON) # JSON field for storing meta data |
| 147 | result_count = Column( |
| 148 | Integer, default=0 |
| 149 | ) # Integer field for storing result count, default 0 |
| 150 | |
| 151 | # Timestamps |
| 152 | created_at = Column(DateTime, server_default=func.now()) |
| 153 | updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now()) |
| 154 | |
| 155 | def to_json(self, with_result=True): |
| 156 | """Serializes all properties of the Task object into a JSON dictionary.""" |
| 157 | return serialize_task(self, with_result) |
no outgoing calls
no test coverage detected