4444@router .get ("/db/all" , status_code = status .HTTP_200_OK , response_model = Page [TL ])
4545async def paged_transcoder_log (params : Params = Depends ()):
4646 async with get_async_session () as session :
47- return await paginate (session , select (TranscoderLog ).order_by (desc (TranscoderLog .transcoder_log_id )), params )
47+ return await paginate (
48+ session ,
49+ select (TranscoderLog ).order_by (desc (TranscoderLog .transcoder_log_id )),
50+ params ,
51+ )
4852
4953
50- @router .get ("/db/search/{query:path}" , status_code = status .HTTP_200_OK , response_model = Page [TL ])
51- async def paged_transcoder_log (query : str , params : Params = Depends ()):
54+ @router .get (
55+ "/db/search/{query:path}" , status_code = status .HTTP_200_OK , response_model = Page [TL ]
56+ )
57+ async def paged_transcoder_log_query (query : str , params : Params = Depends ()):
5258 async with get_async_session () as session :
5359 filters = []
54- filters .append (TranscoderLog .input_string .ilike (f' %{ query } %' ))
55- filters .append (TranscoderLog .uri .ilike (f' %{ query } %' ))
56- filters .append (TranscoderLog .cbor .ilike (f' %{ query } %' ))
60+ filters .append (TranscoderLog .input_string .ilike (f" %{ query } %" ))
61+ filters .append (TranscoderLog .uri .ilike (f" %{ query } %" ))
62+ filters .append (TranscoderLog .cbor .ilike (f" %{ query } %" ))
5763 if query .isdigit ():
5864 filters .append (TranscoderLog .transcoder_log_id == int (query ))
5965
60- return await paginate (session , select (TranscoderLog )
61- .where (or_ (* filters ))
62- .order_by (desc (TranscoderLog .transcoder_log_id )), params )
66+ return await paginate (
67+ session ,
68+ select (TranscoderLog )
69+ .where (or_ (* filters ))
70+ .order_by (desc (TranscoderLog .transcoder_log_id )),
71+ params ,
72+ )
73+
6374
6475@router .get ("/db/id/{id}" , status_code = status .HTTP_200_OK , response_model = TL )
6576def transcoder_log_by_id (id : str ):
6677 return _do_transcoder_log_by_id (id )
67-
78+
79+
6880def _do_transcoder_log_by_id (id : str ):
69- with get_session () as session :
70- return TranscoderLog . query . filter_by ( transcoder_log_id = id ). first ()
81+ return TranscoderLog . query . filter_by ( transcoder_log_id = id ). first ()
82+
7183
7284# PUT /ui/incoming/{cbor}/hex
7385@router .put ("/ui/incoming/{input_cbor}/hex" , status_code = status .HTTP_200_OK )
@@ -80,27 +92,34 @@ async def transcoder_put_cbor_await(cbor: str):
8092 curr_entry = _transcoder_put_cbor (cbor )
8193 transcoder_log_id = curr_entry ["id" ]
8294 while True :
83- with get_session () as session :
84- curr_uri = TranscoderLog .query .filter (TranscoderLog .transcoder_log_id == transcoder_log_id ).first ()
85- if curr_uri .parsed_as != "pending" :
86- if curr_uri .parsed_as == "ERROR" :
87- curr_uri = "ARI://BADARI"
88- else :
89- curr_uri = curr_uri .uri
90- break
95+ curr_uri = TranscoderLog .query .filter (
96+ TranscoderLog .transcoder_log_id == transcoder_log_id
97+ ).first ()
98+ if curr_uri .parsed_as != "pending" :
99+ if curr_uri .parsed_as == "ERROR" :
100+ curr_uri = "ARI://BADARI"
101+ else :
102+ curr_uri = curr_uri .uri
103+ break
91104 time .sleep (1 )
92105
106+ return {"data" : curr_uri }
93107
94- return {"data" : curr_uri }
95108
96109def _transcoder_put_cbor (input_cbor ):
97110 transcoder_log_id = None
98111 send_to_transcode = False
112+ status = "pending"
99113 with get_session () as session :
100- curr_uri = TranscoderLog .query .filter (or_ (TranscoderLog .input_string == input_cbor , TranscoderLog .cbor == input_cbor )).first ()
101-
114+ curr_uri = TranscoderLog .query .filter (
115+ or_ (
116+ TranscoderLog .input_string == input_cbor ,
117+ TranscoderLog .cbor == input_cbor ,
118+ )
119+ ).first ()
120+
102121 if curr_uri is None :
103- c1 = TranscoderLog (input_string = input_cbor , parsed_as = ' pending' )
122+ c1 = TranscoderLog (input_string = input_cbor , parsed_as = " pending" )
104123 session .add (c1 )
105124 session .flush ()
106125 session .refresh (c1 )
@@ -111,8 +130,8 @@ def _transcoder_put_cbor(input_cbor):
111130 # the input_ari has already been submitted
112131 status = "ARI previously submitted, check log"
113132 transcoder_log_id = curr_uri .transcoder_log_id
114-
115- if ( send_to_transcode ) :
133+
134+ if send_to_transcode :
116135 status = "Submitted ARI to transcoder"
117136 TRANSMORGIFIER .transcode (input_cbor )
118137
@@ -124,33 +143,42 @@ def _transcoder_put_cbor(input_cbor):
124143async def transcoder_put_await_str (input_ari : str ):
125144 curr_entry = _transcoder_put_str (input_ari )
126145 transcoder_log_id = curr_entry ["id" ]
127- while (True ):
128- with get_session () as session :
129- curr_uri = TranscoderLog .query .filter_by (transcoder_log_id = transcoder_log_id ).first ()
130- if curr_uri .parsed_as != "pending" :
131- if curr_uri .parsed_as == "ERROR" :
132- curr_uri = "ARI://BADARI"
133- else :
134- curr_uri = curr_uri .uri
135- break
136- time .sleep (1 )
146+ while True :
147+ curr_uri = TranscoderLog .query .filter_by (
148+ transcoder_log_id = transcoder_log_id
149+ ).first ()
150+ if curr_uri .parsed_as != "pending" :
151+ if curr_uri .parsed_as == "ERROR" :
152+ curr_uri = "ARI://BADARI"
153+ else :
154+ curr_uri = curr_uri .uri
155+ break
156+ time .sleep (1 )
157+
158+ return {"data" : curr_uri }
137159
138- return {"data" : curr_uri }
139-
140160
141161# PUT /ui/incoming/str Body is str ARI to send to transcoder
142162@router .put ("/ui/incoming/str" , status_code = status .HTTP_200_OK )
143163def transcoder_incoming_str (input_ari : str ):
144164 return _transcoder_put_str (input_ari )
145165
146- def transcoder_put_str (input_ari : str ):
166+
167+ def _transcoder_put_str (input_ari : str ):
147168 input_ari = input_ari .strip ()
148169 transcoder_log_id = None
149170 send_to_transcode = False
171+ state = "pending"
150172 with get_session () as session :
151- curr_uri = TranscoderLog .query .filter (or_ (TranscoderLog .input_string == input_ari ,TranscoderLog .ari == input_ari , TranscoderLog .cbor == input_ari )).first ()
173+ curr_uri = TranscoderLog .query .filter (
174+ or_ (
175+ TranscoderLog .input_string == input_ari ,
176+ TranscoderLog .ari == input_ari ,
177+ TranscoderLog .cbor == input_ari ,
178+ )
179+ ).first ()
152180 if curr_uri is None :
153- c1 = TranscoderLog (input_string = input_ari , parsed_as = ' pending' )
181+ c1 = TranscoderLog (input_string = input_ari , parsed_as = " pending" )
154182 session .add (c1 )
155183 session .flush ()
156184 session .refresh (c1 )
@@ -161,20 +189,25 @@ def transcoder_put_str(input_ari: str):
161189 # the input_ari has already been submitted
162190 state = "ARI previously submitted, check log"
163191 transcoder_log_id = curr_uri .transcoder_log_id
164-
165- if ( send_to_transcode ) :
192+
193+ if send_to_transcode :
166194 state = "Submitted ARI to transcoder"
167195 TRANSMORGIFIER .transcode (input_ari )
168196
169197 return {"id" : transcoder_log_id , "status" : state }
170198
171199
172200# PUT /ui/incoming_send/str Body is str ARI to send to transcoder
173- @router .put ("/ui/incoming_send/str" , status_code = status .HTTP_200_OK ,
174- responses = {
175- status .HTTP_500_INTERNAL_SERVER_ERROR : {"description" : "Error response from NM" },
176- status .HTTP_504_GATEWAY_TIMEOUT : {"description" : "Manager response timed out" }
177- })
201+ @router .put (
202+ "/ui/incoming_send/str" ,
203+ status_code = status .HTTP_200_OK ,
204+ responses = {
205+ status .HTTP_500_INTERNAL_SERVER_ERROR : {
206+ "description" : "Error response from NM"
207+ },
208+ status .HTTP_504_GATEWAY_TIMEOUT : {"description" : "Manager response timed out" },
209+ },
210+ )
178211async def transcoder_send_ari_str (eid : str , ari : str ):
179212 try :
180213 # Perform translation (API wrapper)
@@ -185,30 +218,34 @@ async def transcoder_send_ari_str(eid: str, ari: str):
185218 while True :
186219 # Wait for request to process before checking state
187220 await asyncio .sleep (1 )
188-
189221 info = _do_transcoder_log_by_id (idinfo ["id" ])
190222
191223 if info .parsed_as != "pending" :
192224 break
193225 if retries <= 0 :
194- raise HTTPException (status_code = status .HTTP_504_GATEWAY_TIMEOUT ,
195- detail = { "idinfo" : idinfo , "info" : info , "status" : "transcoder timeout" })
226+ raise HTTPException (
227+ status_code = status .HTTP_504_GATEWAY_TIMEOUT ,
228+ detail = {
229+ "idinfo" : idinfo ,
230+ "info" : info ,
231+ "status" : "transcoder timeout" ,
232+ },
233+ )
196234
197235 retries -= 1
198236
199237 if info .parsed_as == "ERROR" :
200- raise HTTPException (status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
201- detail = { "idinfo" : idinfo , "info" : info , "status" : 500 })
238+ raise HTTPException (
239+ status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
240+ detail = {"idinfo" : idinfo , "info" : info , "status" : 500 },
241+ )
202242
203243 # Publish
204- state = do_nm_put_hex_eid ( eid , info .cbor )
205- return { "idinfo" : idinfo , "info" : info , "status" : state }
244+ state = do_nm_put_hex_eid (eid , info .cbor )
245+ return {"idinfo" : idinfo , "info" : info , "status" : state }
206246 except HTTPException as e :
207- e .detail = { "idinfo" : idinfo , "info" : info , "status" : e .status_code }
247+ e .detail = {"idinfo" : idinfo , "info" : info , "status" : e .status_code }
208248 raise e
209249 except Exception as e :
210250 logger .exception (e )
211251 raise HTTPException (status_code = status .HTTP_500_INTERNAL_SERVER_ERROR )
212-
213-
214-
0 commit comments