(obj: Task, withResult: boolean)
| 216 | } |
| 217 | |
| 218 | async function serializeTask(obj: Task, withResult: boolean): Promise<any> { |
| 219 | const taskId = obj.id; |
| 220 | const status = obj.status; |
| 221 | let result = {}; |
| 222 | |
| 223 | if (withResult) { |
| 224 | result = await fetchTaskResult(status, result, obj, taskId) |
| 225 | } |
| 226 | return { |
| 227 | id: taskId, |
| 228 | status: status, |
| 229 | task_name: createTaskName(obj.task_name, taskId), |
| 230 | scraper_name: obj.scraper_name, |
| 231 | scraper_type: obj.scraper_type, |
| 232 | is_all_task: obj.is_all_task, |
| 233 | priority: obj.priority, |
| 234 | is_large: obj.is_large, |
| 235 | parent_task_id: obj.parent_task_id, |
| 236 | duration: calculateDuration(obj), |
| 237 | started_at: isoformat(obj.started_at), |
| 238 | finished_at: isoformat(obj.finished_at), |
| 239 | data: obj.data, |
| 240 | metadata: obj.meta_data, |
| 241 | ...result, |
| 242 | result_count: obj.result_count, |
| 243 | created_at: isoformat(obj.created_at), |
| 244 | updated_at: isoformat(obj.updated_at), |
| 245 | }; |
| 246 | } |
| 247 | export type StatusKind = typeof TaskStatus[keyof typeof TaskStatus] |
| 248 | |
| 249 | // Task model |
no test coverage detected