@@ -39,6 +39,7 @@ use crate::indexer::deserialize_index;
39
39
use crate :: indexer:: operations_to_point_operations;
40
40
use crate :: indexer:: search;
41
41
use crate :: indexer:: serialize_index;
42
+ use crate :: indexer:: IndexError ;
42
43
use crate :: indexer:: Point ;
43
44
use crate :: indexer:: PointOperation ;
44
45
use crate :: indexer:: SearchError ;
@@ -244,7 +245,7 @@ fn uri_to_spec(uri: &Uri) -> Result<ResourceSpec, SpecParseError> {
244
245
#[ derive( Clone , Debug ) ]
245
246
pub enum TaskStatus {
246
247
Pending ( f32 ) ,
247
- Error ,
248
+ Error ( String ) ,
248
249
Completed ,
249
250
}
250
251
@@ -422,6 +423,7 @@ impl Service {
422
423
api_key : String ,
423
424
) -> Result < ( ) , StartIndexError > {
424
425
let content_endpoint = self . content_endpoint . clone ( ) ;
426
+ let internal_task_id = task_id. clone ( ) ;
425
427
if let Some ( content_endpoint) = content_endpoint {
426
428
tokio:: spawn ( async move {
427
429
let index_id = create_index_name ( & domain, & commit) ;
@@ -436,13 +438,24 @@ impl Service {
436
438
. await
437
439
. unwrap ( )
438
440
. chunks ( 100 ) ;
439
- let ( id , hnsw ) = self
441
+ match self
440
442
. process_operation_chunks (
441
443
opstream, domain, commit, previous, & index_id, & task_id, & api_key,
442
444
)
443
- . await ;
444
- self . set_index ( id, hnsw. into ( ) ) . await ;
445
- self . clear_pending ( & index_id) . await ;
445
+ . await
446
+ {
447
+ Ok ( ( id, hnsw) ) => {
448
+ self . set_index ( id, hnsw. into ( ) ) . await ;
449
+ self . clear_pending ( & index_id) . await ;
450
+ }
451
+ Err ( err) => {
452
+ self . set_task_status (
453
+ internal_task_id,
454
+ TaskStatus :: Error ( err. to_string ( ) ) ,
455
+ )
456
+ . await ;
457
+ }
458
+ }
446
459
}
447
460
self . set_task_status ( task_id, TaskStatus :: Completed ) . await ;
448
461
} ) ;
@@ -471,6 +484,7 @@ impl Service {
471
484
Ok ( ( ) )
472
485
}
473
486
487
+ #[ allow( clippy:: too_many_arguments) ]
474
488
async fn process_operation_chunks (
475
489
self : & Arc < Self > ,
476
490
mut opstream : futures:: stream:: Chunks <
@@ -482,7 +496,7 @@ impl Service {
482
496
index_id : & str ,
483
497
task_id : & str ,
484
498
api_key : & str ,
485
- ) -> ( String , HnswIndex ) {
499
+ ) -> Result < ( String , HnswIndex ) , IndexError > {
486
500
let id = create_index_name ( & domain, & commit) ;
487
501
let mut hnsw = self
488
502
. load_hnsw_for_indexing ( IndexIdentifier {
@@ -500,14 +514,14 @@ impl Service {
500
514
structs,
501
515
api_key,
502
516
)
503
- . await ;
504
- hnsw = start_indexing_from_operations ( hnsw, new_ops) . unwrap ( ) ;
517
+ . await ? ;
518
+ hnsw = start_indexing_from_operations ( hnsw, new_ops) ? ;
505
519
}
506
520
self . set_task_status ( task_id. to_string ( ) , TaskStatus :: Pending ( 0.8 ) )
507
521
. await ;
508
522
let path = self . path . clone ( ) ;
509
- serialize_index ( path, index_id, hnsw. clone ( ) ) . unwrap ( ) ;
510
- ( id, hnsw)
523
+ serialize_index ( path, index_id, hnsw. clone ( ) ) ? ;
524
+ Ok ( ( id, hnsw) )
511
525
}
512
526
513
527
async fn get_start_index (
@@ -526,7 +540,7 @@ impl Service {
526
540
527
541
async fn get ( self : Arc < Self > , req : Request < Body > ) -> Result < Response < Body > , Infallible > {
528
542
let uri = req. uri ( ) ;
529
- match dbg ! ( uri_to_spec( uri) ) {
543
+ match uri_to_spec ( uri) {
530
544
Ok ( ResourceSpec :: StartIndex {
531
545
domain,
532
546
commit,
@@ -557,8 +571,9 @@ impl Service {
557
571
TaskStatus :: Pending ( f) => {
558
572
Ok ( Response :: builder ( ) . body ( format ! ( "{}" , f) . into ( ) ) . unwrap ( ) )
559
573
}
560
- TaskStatus :: Error => Ok ( Response :: builder ( )
561
- . body ( format ! ( "{:?}" , state) . into ( ) )
574
+ TaskStatus :: Error ( msg) => Ok ( Response :: builder ( )
575
+ . status ( StatusCode :: INTERNAL_SERVER_ERROR )
576
+ . body ( format ! ( "{:?}" , msg) . into ( ) )
562
577
. unwrap ( ) ) ,
563
578
TaskStatus :: Completed => {
564
579
Ok ( Response :: builder ( ) . body ( format ! ( "{}" , 1.0 ) . into ( ) ) . unwrap ( ) )
0 commit comments