|
45 | 45 | LoopItemUpdate, |
46 | 46 | MyWorkItemResponse, |
47 | 47 | MyWorkListResponse, |
48 | | - RuntimeTaskTrack, |
49 | | - RuntimeTaskTrackingStatusUpdate, |
50 | | - RuntimeTaskTrackResponse, |
51 | 48 | ) |
52 | 49 | from app.services.cloud_projects import cloud_project_service |
53 | 50 | from app.services.delivery import delivery_service |
@@ -197,109 +194,6 @@ def bind_cloud_project_task( |
197 | 194 | return LoopItemTaskBindingResponse.model_validate(binding) |
198 | 195 |
|
199 | 196 |
|
200 | | -def _tracked_item_response( |
201 | | - db: Session, |
202 | | - item_id: str, |
203 | | - current_user: User, |
204 | | -) -> LoopItemResponse: |
205 | | - if external_loop_item_provider.is_external_item(db, item_id): |
206 | | - return LoopItemResponse.model_validate( |
207 | | - external_loop_item_provider.get(db, item_id, current_user.id) |
208 | | - ) |
209 | | - item = loop_item_service.get(db, item_id, current_user.id) |
210 | | - return _loop_item_response(db, item, current_user) |
211 | | - |
212 | | - |
213 | | -@router.post( |
214 | | - "/cloud-projects/{project_id}/tasks/track", |
215 | | - response_model=RuntimeTaskTrackResponse, |
216 | | - status_code=status.HTTP_201_CREATED, |
217 | | -) |
218 | | -def track_cloud_project_task( |
219 | | - project_id: int, |
220 | | - values: RuntimeTaskTrack, |
221 | | - db: Session = Depends(get_db), |
222 | | - current_user: User = Depends(get_current_user), |
223 | | -) -> RuntimeTaskTrackResponse: |
224 | | - existing = loop_item_service.find_active_task_binding( |
225 | | - db, current_user.id, values.device_id, values.task_id |
226 | | - ) |
227 | | - if existing is not None and existing.loop_item_id: |
228 | | - if str(existing.cloud_project_id) != str(project_id): |
229 | | - raise HTTPException( |
230 | | - status.HTTP_409_CONFLICT, |
231 | | - "Runtime task is already tracked by another project", |
232 | | - ) |
233 | | - return RuntimeTaskTrackResponse( |
234 | | - item=_tracked_item_response(db, existing.loop_item_id, current_user), |
235 | | - binding=LoopItemTaskBindingResponse.model_validate(existing), |
236 | | - ) |
237 | | - |
238 | | - project = cloud_project_service.get(db, project_id, current_user.id) |
239 | | - created = loop_item_provider_router.create( |
240 | | - db, |
241 | | - project, |
242 | | - current_user, |
243 | | - LoopItemCreate( |
244 | | - title=values.task_title, |
245 | | - description=values.description, |
246 | | - status="in_progress", |
247 | | - ), |
248 | | - ) |
249 | | - item_id = str(created.values["id"]) |
250 | | - external_loop_item_provider.ensure_shadow(db, item_id, current_user.id) |
251 | | - binding = loop_item_service.bind_task( |
252 | | - db, item_id, values.binding(), current_user.id |
253 | | - ) |
254 | | - return RuntimeTaskTrackResponse( |
255 | | - item=LoopItemResponse.model_validate(created.values), |
256 | | - binding=LoopItemTaskBindingResponse.model_validate(binding), |
257 | | - ) |
258 | | - |
259 | | - |
260 | | -@router.patch( |
261 | | - "/runtime-tasks/cloud-context/tracking-status", |
262 | | - response_model=LoopItemResponse | None, |
263 | | -) |
264 | | -def update_runtime_task_tracking_status( |
265 | | - values: RuntimeTaskTrackingStatusUpdate, |
266 | | - db: Session = Depends(get_db), |
267 | | - current_user: User = Depends(get_current_user), |
268 | | -) -> LoopItemResponse | None: |
269 | | - binding = loop_item_service.find_active_task_binding( |
270 | | - db, current_user.id, values.device_id, values.task_id |
271 | | - ) |
272 | | - if binding is None or not binding.loop_item_id: |
273 | | - return None |
274 | | - item = _tracked_item_response(db, binding.loop_item_id, current_user) |
275 | | - next_status: str | None = None |
276 | | - if values.execution_status == "running" and item.status in { |
277 | | - "inbox", |
278 | | - "pending", |
279 | | - "in_review", |
280 | | - }: |
281 | | - next_status = "in_progress" |
282 | | - elif values.execution_status == "succeeded" and item.status == "in_progress": |
283 | | - next_status = "in_review" |
284 | | - if next_status is None: |
285 | | - return item |
286 | | - if external_loop_item_provider.is_external_item(db, item.id): |
287 | | - updated = external_loop_item_provider.update( |
288 | | - db, |
289 | | - item.id, |
290 | | - current_user.id, |
291 | | - LoopItemUpdate(version=item.version, status=next_status), |
292 | | - ) |
293 | | - return LoopItemResponse.model_validate(updated) |
294 | | - stored = loop_item_service.update( |
295 | | - db, |
296 | | - item.id, |
297 | | - current_user.id, |
298 | | - LoopItemUpdate(version=item.version, status=next_status), |
299 | | - ) |
300 | | - return _loop_item_response(db, stored, current_user) |
301 | | - |
302 | | - |
303 | 197 | @router.delete("/runtime-tasks/cloud-context", status_code=status.HTTP_204_NO_CONTENT) |
304 | 198 | def unbind_runtime_task_cloud_context( |
305 | 199 | values: LoopItemTaskBind, |
|
0 commit comments