tomoya 2 nedēļas atpakaļ
vecāks
revīzija
3721fa5bdd
1 mainītis faili ar 37 papildinājumiem un 20 dzēšanām
  1. 37 20
      backend/app/app/api/api_v1/endpoints/edm_saas_api.py

+ 37 - 20
backend/app/app/api/api_v1/endpoints/edm_saas_api.py

@@ -177,28 +177,45 @@ async def wait_finish(video_data:dict):
             break
 
     if task.state == "SUCCESS":
-        video = supabase.table(VIDEO_TABLE).update({"progress_state":"SUCCESS"}).eq('id', video_data['id']).execute()
-        if time := task.result:
-            # user.available_time -= int(time) if int(time) <= user.available_time else 0
-            # video.length = int(time)
-            pass
-        msg_data = f"{video_data['stored_filename']}:SUCCESS:{int(time)}"
-        headers = {
-            'Authorization': 'Bearer ' + LINE_TOKEN    
-        }
-        data = {
-            'message':f'cloud-choozmo-com\n \
-                        Video\n \
-                        user: {video_data["owner_id"]}\n \
-                        membership: {video_data["membership_status"]}\n \
-                        video: {video_data["id"]}\n \
-                        state: success'    
-        }
-        data = requests.post(LINE_URL, headers=headers, data=data) 
+        
+        if (time := task.result) and str(time).isdigit():
+            video = supabase.table(VIDEO_TABLE).update({"progress_state":"SUCCESS"}).eq('id', video_data['id']).execute()
+            if time := task.result:
+                # user.available_time -= int(time) if int(time) <= user.available_time else 0
+                # video.length = int(time)
+                pass
+            msg_data = f"{video_data['stored_filename']}:SUCCESS:{int(time)}"
+            headers = {
+                'Authorization': 'Bearer ' + LINE_TOKEN    
+            }
+            data = {
+                'message':f'cloud-choozmo-com\n \
+                            Video\n \
+                            user: {video_data["owner_id"]}\n \
+                            membership: {video_data["membership_status"]}\n \
+                            video: {video_data["id"]}\n \
+                            state: success'    
+            }
+            data = requests.post(LINE_URL, headers=headers, data=data) 
+        
+        else:
+            video = supabase.table(VIDEO_TABLE).update({"progress_state":"FAILUR", "error_message":str(task.result)}).eq('id', video_data['id']).execute()
+            msg_data = f"{video_data['stored_filename']}:FAILURE:{task.result}"
+            headers = {
+                'Authorization': 'Bearer ' + LINE_TOKEN    
+            }
+            data = {
+                'message':f'cloud-choozmo-com\n \
+                            Video\n \
+                            user: {video_data["owner_id"]}\n \
+                            membership: {video_data["membership_status"]}\n \
+                            video: {video_data["id"]}\n \
+                            state: success'    
+            }
 
     elif task.state == "FAILURE":
-        video = supabase.table(VIDEO_TABLE).update({"progress_state":"FAILURE"}).eq('id', video_data['id']).execute()
-        msg_data = f"{video_data['stored_filename']}:FAILURE"
+        video = supabase.table(VIDEO_TABLE).update({"progress_state":"FAILURE", "error_message":str(task.result)}).eq('id', video_data['id']).execute()
+        msg_data = f"{video_data['stored_filename']}:FAILURE:{task.result}"
 
         headers = {
             'Authorization': 'Bearer ' + LINE_TOKEN