def delete_session():
"""
The ProxySession resource endpoint for removing a ProxySession
to the pool.
"""
body = request.json
try:
session_id = str(body['session_id'])
except (KeyError):
raise InvalidAPIUsage(
"Required argument: 'session_id' (str)",
payload={'reason':
'invalidAPIUsage'})
try:
session = ProxySession.query.filter_by(id=session_id).one()
except NoResultFound:
msg = ("ProxySession {} could not be deleted because"
" it does not exist".format(session_id))
log.info({"message": msg,
"status": "failed"})
raise InvalidAPIUsage(
msg, status_code=404,
payload={'reason':
'ProxySession not found'})
participant_a, participant_b, virtual_tn = ProxySession.terminate(
session_id)
recipients = [participant_a, participant_b]
send_message(
recipients,
virtual_tn.value,
SESSION_END_MSG,
session_id,
is_system_msg=True)
msg = "Ended session {} and released {} back to pool".format(
session_id, virtual_tn.value)
log.info({"message": msg, "status": "succeeded"})
return Response(
json.dumps({"message": "Successfully ended the session.",
"status": "succeeded",
"session_id": session_id}),
content_type="application/json")
评论列表
文章目录