Advertisement
Iam_Sandeep

Untitled

Apr 22nd, 2024
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. @router.post(
  2.     "/worker/cancel_backup_task",
  3.     summary="cancel booked task by worker.This doesnt store time stamp operation"
  4. )
  5. async def cancel_backup_task(
  6.         user: dict = Depends(worker_resolver),
  7.         task: dict = Depends(in_progress_task_resolver)
  8. ):
  9.     await MONGO_CLIENT.in_progress_tasks.delete(task['_id'])
  10.     await collect_time_stamp_for_customer('in_progress_tasks_deletion_time_stamp', user, task)
  11.     await MONGO_CLIENT.pending_tasks.pull({'_id': user['_id'], 'tasks': task})
  12.     await MONGO_CLIENT.pending_tasks.pull({'_id': task['customer_id'], 'tasks': task})
  13.     time_left_to_start_task_in_hours = ((task['task_details'][
  14.                                              'start'] - datetime.datetime.now()).total_seconds()) / 3600
  15.     if time_left_to_start_task_in_hours >= 1:
  16.         await MONGO_CLIENT.instant_tasks.insert(task)
  17.         return JSONResponse({
  18.             'code': 1,
  19.             'content': {'message': "Moved to Instant Tasks"}
  20.         })
  21.     else:
  22.         # Do refund
  23.         await MONGO_CLIENT.cancelled_tasks.insert(task)
  24.         return JSONResponse({
  25.             'code': 1,
  26.             'content': {'message': "Backup Task has been Cancelled"}
  27.         })
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement