@@ -24,12 +24,11 @@ use axum_extra::{
24
24
headers:: { authorization:: Bearer , Authorization , CacheControl , ETag , IfNoneMatch } ,
25
25
TypedHeader ,
26
26
} ;
27
- use futures:: { future :: BoxFuture , FutureExt , TryFutureExt } ;
27
+ use futures:: { FutureExt , TryFutureExt } ;
28
28
use orchestrator:: coordinator:: { self , CoordinatorFactory , DockerBackend , TRACKED_CONTAINERS } ;
29
29
use snafu:: prelude:: * ;
30
30
use std:: {
31
31
convert:: TryInto ,
32
- future:: Future ,
33
32
mem, path,
34
33
str:: FromStr ,
35
34
sync:: { Arc , LazyLock } ,
@@ -134,7 +133,8 @@ pub(crate) async fn serve(config: Config) {
134
133
let x_request_id = HeaderName :: from_static ( "x-request-id" ) ;
135
134
136
135
// Basic access logging
137
- app = app. layer (
136
+ app = app. layer ( {
137
+ let x_request_id = x_request_id. clone ( ) ;
138
138
TraceLayer :: new_for_http ( ) . make_span_with ( move |req : & Request < _ > | {
139
139
const REQUEST_ID : & str = "request_id" ;
140
140
@@ -152,17 +152,15 @@ pub(crate) async fn serve(config: Config) {
152
152
}
153
153
154
154
span
155
- } ) ,
156
- ) ;
157
-
158
- let x_request_id = HeaderName :: from_static ( "x-request-id" ) ;
155
+ } )
156
+ } ) ;
159
157
160
158
// propagate `x-request-id` headers from request to response
161
159
app = app. layer ( PropagateRequestIdLayer :: new ( x_request_id. clone ( ) ) ) ;
162
160
163
161
app = app. layer ( SetRequestIdLayer :: new (
164
162
x_request_id. clone ( ) ,
165
- MakeRequestUuid :: default ( ) ,
163
+ MakeRequestUuid ,
166
164
) ) ;
167
165
168
166
let server_socket_addr = config. server_socket_addr ( ) ;
@@ -208,16 +206,15 @@ async fn rewrite_help_as_index(
208
206
next. run ( req) . await
209
207
}
210
208
211
- async fn attempt_record_request < T , RFut , RT , RE > (
209
+ async fn attempt_record_request < R , T , E > (
212
210
db : Handle ,
213
- req : T ,
214
- f : impl FnOnce ( T ) -> RFut ,
215
- ) -> Result < RT , RE >
211
+ req : R ,
212
+ f : impl AsyncFnOnce ( R ) -> Result < T , E > ,
213
+ ) -> Result < T , E >
216
214
where
217
- T : HasEndpoint + serde:: Serialize ,
218
- RFut : Future < Output = Result < RT , RE > > ,
215
+ R : HasEndpoint + serde:: Serialize ,
219
216
{
220
- let category = format ! ( "http.{}" , <& str >:: from( T :: ENDPOINT ) ) ;
217
+ let category = format ! ( "http.{}" , <& str >:: from( R :: ENDPOINT ) ) ;
221
218
let payload = serde_json:: to_string ( & req) . unwrap_or_else ( |_| String :: from ( "<invalid JSON>" ) ) ;
222
219
let guard = db. start_with_guard ( category, payload) . await ;
223
220
@@ -233,9 +230,9 @@ async fn evaluate(
233
230
Extension ( db) : Extension < Handle > ,
234
231
Json ( req) : Json < api:: EvaluateRequest > ,
235
232
) -> Result < Json < api:: EvaluateResponse > > {
236
- attempt_record_request ( db, req, |req| async {
237
- with_coordinator ( & factory. 0 , req, |c, req| {
238
- c. execute ( req) . context ( EvaluateSnafu ) . boxed ( )
233
+ attempt_record_request ( db, req, async |req| {
234
+ with_coordinator ( & factory. 0 , req, async |c, req| {
235
+ c. execute ( req) . context ( EvaluateSnafu ) . await
239
236
} )
240
237
. await
241
238
. map ( Json )
@@ -248,9 +245,9 @@ async fn compile(
248
245
Extension ( db) : Extension < Handle > ,
249
246
Json ( req) : Json < api:: CompileRequest > ,
250
247
) -> Result < Json < api:: CompileResponse > > {
251
- attempt_record_request ( db, req, |req| async {
252
- with_coordinator ( & factory. 0 , req, |c, req| {
253
- c. compile ( req) . context ( CompileSnafu ) . boxed ( )
248
+ attempt_record_request ( db, req, async |req| {
249
+ with_coordinator ( & factory. 0 , req, async |c, req| {
250
+ c. compile ( req) . context ( CompileSnafu ) . await
254
251
} )
255
252
. await
256
253
. map ( Json )
@@ -263,9 +260,9 @@ async fn execute(
263
260
Extension ( db) : Extension < Handle > ,
264
261
Json ( req) : Json < api:: ExecuteRequest > ,
265
262
) -> Result < Json < api:: ExecuteResponse > > {
266
- attempt_record_request ( db, req, |req| async {
267
- with_coordinator ( & factory. 0 , req, |c, req| {
268
- c. execute ( req) . context ( ExecuteSnafu ) . boxed ( )
263
+ attempt_record_request ( db, req, async |req| {
264
+ with_coordinator ( & factory. 0 , req, async |c, req| {
265
+ c. execute ( req) . context ( ExecuteSnafu ) . await
269
266
} )
270
267
. await
271
268
. map ( Json )
@@ -278,9 +275,9 @@ async fn format(
278
275
Extension ( db) : Extension < Handle > ,
279
276
Json ( req) : Json < api:: FormatRequest > ,
280
277
) -> Result < Json < api:: FormatResponse > > {
281
- attempt_record_request ( db, req, |req| async {
282
- with_coordinator ( & factory. 0 , req, |c, req| {
283
- c. format ( req) . context ( FormatSnafu ) . boxed ( )
278
+ attempt_record_request ( db, req, async |req| {
279
+ with_coordinator ( & factory. 0 , req, async |c, req| {
280
+ c. format ( req) . context ( FormatSnafu ) . await
284
281
} )
285
282
. await
286
283
. map ( Json )
@@ -293,9 +290,9 @@ async fn clippy(
293
290
Extension ( db) : Extension < Handle > ,
294
291
Json ( req) : Json < api:: ClippyRequest > ,
295
292
) -> Result < Json < api:: ClippyResponse > > {
296
- attempt_record_request ( db, req, |req| async {
297
- with_coordinator ( & factory. 0 , req, |c, req| {
298
- c. clippy ( req) . context ( ClippySnafu ) . boxed ( )
293
+ attempt_record_request ( db, req, async |req| {
294
+ with_coordinator ( & factory. 0 , req, async |c, req| {
295
+ c. clippy ( req) . context ( ClippySnafu ) . await
299
296
} )
300
297
. await
301
298
. map ( Json )
@@ -308,9 +305,9 @@ async fn miri(
308
305
Extension ( db) : Extension < Handle > ,
309
306
Json ( req) : Json < api:: MiriRequest > ,
310
307
) -> Result < Json < api:: MiriResponse > > {
311
- attempt_record_request ( db, req, |req| async {
312
- with_coordinator ( & factory. 0 , req, |c, req| {
313
- c. miri ( req) . context ( MiriSnafu ) . boxed ( )
308
+ attempt_record_request ( db, req, async |req| {
309
+ with_coordinator ( & factory. 0 , req, async |c, req| {
310
+ c. miri ( req) . context ( MiriSnafu ) . await
314
311
} )
315
312
. await
316
313
. map ( Json )
@@ -323,9 +320,9 @@ async fn macro_expansion(
323
320
Extension ( db) : Extension < Handle > ,
324
321
Json ( req) : Json < api:: MacroExpansionRequest > ,
325
322
) -> Result < Json < api:: MacroExpansionResponse > > {
326
- attempt_record_request ( db, req, |req| async {
327
- with_coordinator ( & factory. 0 , req, |c, req| {
328
- c. macro_expansion ( req) . context ( MacroExpansionSnafu ) . boxed ( )
323
+ attempt_record_request ( db, req, async |req| {
324
+ with_coordinator ( & factory. 0 , req, async |c, req| {
325
+ c. macro_expansion ( req) . context ( MacroExpansionSnafu ) . await
329
326
} )
330
327
. await
331
328
. map ( Json )
@@ -433,10 +430,10 @@ impl Outcome {
433
430
}
434
431
}
435
432
436
- async fn with_coordinator < WebReq , WebResp , Req , Resp , F > (
433
+ async fn with_coordinator < WebReq , WebResp , Req , Resp > (
437
434
factory : & CoordinatorFactory ,
438
435
req : WebReq ,
439
- f : F ,
436
+ f : impl AsyncFnOnce ( & coordinator :: Coordinator < DockerBackend > , Req ) -> Result < Resp > ,
440
437
) -> Result < WebResp >
441
438
where
442
439
WebReq : TryInto < Req > ,
@@ -445,8 +442,6 @@ where
445
442
Req : HasLabelsCore ,
446
443
Resp : Into < WebResp > ,
447
444
Resp : IsSuccess ,
448
- for < ' f > F :
449
- FnOnce ( & ' f coordinator:: Coordinator < DockerBackend > , Req ) -> BoxFuture < ' f , Result < Resp > > ,
450
445
{
451
446
let coordinator = factory. build ( ) ;
452
447
@@ -525,9 +520,8 @@ where
525
520
. with_max_age ( SANDBOX_CACHE_TIME_TO_LIVE )
526
521
. with_public ( ) ;
527
522
528
- let use_fresh = if_none_match. map_or ( true , |if_none_match| {
529
- if_none_match. 0 . precondition_passes ( & etag)
530
- } ) ;
523
+ let use_fresh =
524
+ if_none_match. is_none_or ( |if_none_match| if_none_match. 0 . precondition_passes ( & etag) ) ;
531
525
532
526
let etag = TypedHeader ( etag) ;
533
527
let cache_control = TypedHeader ( cache_control) ;
@@ -617,7 +611,7 @@ async fn nowebsocket(Json(req): Json<NoWebSocketRequest>) {
617
611
}
618
612
619
613
static WS_ERRORS : LazyLock < std:: sync:: Mutex < std:: collections:: HashMap < String , usize > > > =
620
- LazyLock :: new ( || Default :: default ( ) ) ;
614
+ LazyLock :: new ( Default :: default) ;
621
615
622
616
fn record_websocket_error ( error : String ) {
623
617
* WS_ERRORS
0 commit comments