MCPcopy Create free account
hub / github.com/omkarcloud/botasaurus / serialize_task

Function serialize_task

botasaurus_server/botasaurus_server/models.py:85–119  ·  view source on GitHub ↗
(obj, with_result)

Source from the content-addressed store, hash-verified

83
84
85def serialize_task(obj, with_result):
86 task_id = obj.id
87 status = obj.status
88 if with_result:
89 if status == TaskStatus.PENDING:
90 result = {"result": None}
91 elif status != TaskStatus.IN_PROGRESS or obj.is_all_task:
92 # set in cache
93 if not hasattr(obj, "result"):
94 result = {"result": TaskResults.get_all_task(task_id) if obj.is_all_task else TaskResults.get_task(task_id)}
95 else:
96 result = {"result": obj.result}
97 else:
98 result = {"result": None}
99 else:
100 result = {}
101 return {
102 "id": task_id,
103 "status": status,
104 "task_name": create_task_name(obj.task_name, task_id),
105 "scraper_name": obj.scraper_name,
106 "scraper_type": obj.scraper_type,
107 "is_all_task": obj.is_all_task,
108 "is_sync": obj.is_sync,
109 "parent_task_id": obj.parent_task_id,
110 "duration": calculate_duration(obj),
111 "started_at": isoformat(obj.started_at),
112 "finished_at": isoformat(obj.finished_at),
113 "data": obj.data,
114 "metadata": obj.meta_data,
115 **result,
116 "result_count": obj.result_count,
117 "created_at": isoformat(obj.created_at),
118 "updated_at": isoformat(obj.updated_at),
119 }
120
121
122class Task(Base):

Callers 1

to_jsonMethod · 0.85

Calls 5

create_task_nameFunction · 0.85
calculate_durationFunction · 0.85
get_all_taskMethod · 0.80
isoformatFunction · 0.70
get_taskMethod · 0.45

Tested by

no test coverage detected