@@ -395,6 +395,12 @@ impl Service {
395
395
}
396
396
397
397
async fn serve ( self : Arc < Self > , req : Request < Body > ) -> Result < Response < Body > , Infallible > {
398
+ eprintln ! (
399
+ "{:?}: {:?} {:?}" ,
400
+ chrono:: offset:: Local :: now( ) ,
401
+ req. method( ) ,
402
+ req. uri( )
403
+ ) ;
398
404
match * req. method ( ) {
399
405
Method :: POST => self . post ( req) . await ,
400
406
Method :: GET => self . get ( req) . await ,
@@ -414,6 +420,32 @@ impl Service {
414
420
}
415
421
}
416
422
423
+ async fn start_indexing_inner (
424
+ self : Arc < Self > ,
425
+ domain : String ,
426
+ commit : String ,
427
+ previous : Option < String > ,
428
+ task_id : & str ,
429
+ api_key : String ,
430
+ index_id : & str ,
431
+ content_endpoint : String ,
432
+ ) -> Result < ( String , HnswIndex ) , IndexError > {
433
+ let internal_task_id = task_id. clone ( ) ;
434
+ let opstream = get_operations_from_content_endpoint (
435
+ content_endpoint. to_string ( ) ,
436
+ self . user_forward_header . clone ( ) ,
437
+ domain. clone ( ) ,
438
+ commit. clone ( ) ,
439
+ previous. clone ( ) ,
440
+ )
441
+ . await ?
442
+ . chunks ( 100 ) ;
443
+ self . process_operation_chunks (
444
+ opstream, domain, commit, previous, index_id, task_id, & api_key,
445
+ )
446
+ . await
447
+ }
448
+
417
449
fn start_indexing (
418
450
self : Arc < Self > ,
419
451
domain : String ,
@@ -428,36 +460,39 @@ impl Service {
428
460
tokio:: spawn ( async move {
429
461
let index_id = create_index_name ( & domain, & commit) ;
430
462
if self . test_and_set_pending ( index_id. clone ( ) ) . await {
431
- let opstream = get_operations_from_content_endpoint (
432
- content_endpoint. to_string ( ) ,
433
- self . user_forward_header . clone ( ) ,
434
- domain. clone ( ) ,
435
- commit. clone ( ) ,
436
- previous. clone ( ) ,
437
- )
438
- . await
439
- . unwrap ( )
440
- . chunks ( 100 ) ;
441
463
match self
442
- . process_operation_chunks (
443
- opstream, domain, commit, previous, & index_id, & task_id, & api_key,
464
+ . clone ( )
465
+ . start_indexing_inner (
466
+ domain,
467
+ commit,
468
+ previous,
469
+ & task_id,
470
+ api_key,
471
+ & index_id,
472
+ content_endpoint,
444
473
)
445
474
. await
446
475
{
447
476
Ok ( ( id, hnsw) ) => {
448
477
self . set_index ( id, hnsw. into ( ) ) . await ;
478
+ self . set_task_status ( task_id, TaskStatus :: Completed ) . await ;
449
479
self . clear_pending ( & index_id) . await ;
450
480
}
451
481
Err ( err) => {
482
+ eprintln ! (
483
+ "{:?}: error while indexing: {:?}" ,
484
+ chrono:: offset:: Local :: now( ) ,
485
+ err
486
+ ) ;
452
487
self . set_task_status (
453
488
internal_task_id,
454
489
TaskStatus :: Error ( err. to_string ( ) ) ,
455
490
)
456
491
. await ;
492
+ self . clear_pending ( & index_id) . await ;
457
493
}
458
494
}
459
495
}
460
- self . set_task_status ( task_id, TaskStatus :: Completed ) . await ;
461
496
} ) ;
462
497
Ok ( ( ) )
463
498
} else {
@@ -577,7 +612,7 @@ impl Service {
577
612
}
578
613
}
579
614
} else {
580
- Ok ( Response :: builder ( ) . body ( format ! ( "{}" , 1.0 ) . into ( ) ) . unwrap ( ) )
615
+ Ok ( Response :: builder ( ) . status ( 404 ) . body ( Body :: empty ( ) ) . unwrap ( ) )
581
616
}
582
617
}
583
618
Ok ( ResourceSpec :: DuplicateCandidates {
0 commit comments