m8chaa commited on
Commit
75eae6d
·
verified ·
1 Parent(s): 10a6211

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -1092,8 +1092,21 @@ async def notifications(request: Request, background_tasks: BackgroundTasks):
1092
 
1093
  else:
1094
  logging.warning(f"Received notification for unknown channel: {channel_id}")
 
1095
 
1096
  return {"message": "Notification processed successfully"}
1097
  except Exception as e:
1098
  logging.error(f"Error processing notification: {str(e)}")
1099
- raise HTTPException(status_code=500, detail=str(e))
 
 
 
 
 
 
 
 
 
 
 
 
 
1092
 
1093
  else:
1094
  logging.warning(f"Received notification for unknown channel: {channel_id}")
1095
+ background_tasks.add_task(stop_channel, channel_id, resource_id)
1096
 
1097
  return {"message": "Notification processed successfully"}
1098
  except Exception as e:
1099
  logging.error(f"Error processing notification: {str(e)}")
1100
+ raise HTTPException(status_code=500, detail=str(e))
1101
+
1102
+ def stop_channel(channel_id, resource_id):
1103
+ request_body = {
1104
+ 'id': channel_id,
1105
+ 'resourceId': resource_id
1106
+ }
1107
+
1108
+ try:
1109
+ service.channels().stop(body=request_body).execute()
1110
+ print(f"Channel {channel_id} stopped successfully.")
1111
+ except Exception as e:
1112
+ print(f"An error occurred: {e}")