@@ -406,13 +406,52 @@ pub struct TasksQuery<'a> {
406
406
pub client : & ' a Client ,
407
407
// Index uids array to only retrieve the tasks of the indexes.
408
408
#[ serde( skip_serializing_if = "Option::is_none" ) ]
409
- pub index_uid : Option < Vec < & ' a str > > ,
409
+ pub index_uids : Option < Vec < & ' a str > > ,
410
410
// Statuses array to only retrieve the tasks with these statuses.
411
411
#[ serde( skip_serializing_if = "Option::is_none" ) ]
412
- pub status : Option < Vec < & ' a str > > ,
412
+ pub statuses : Option < Vec < & ' a str > > ,
413
413
// Types array to only retrieve the tasks with these [TaskType].
414
- #[ serde( skip_serializing_if = "Option::is_none" , rename = "type" ) ]
415
- pub task_type : Option < Vec < & ' a str > > ,
414
+ #[ serde( skip_serializing_if = "Option::is_none" , rename = "types" ) ]
415
+ pub task_types : Option < Vec < & ' a str > > ,
416
+ // Uids of the tasks to retrieve
417
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
418
+ pub uids : Option < Vec < & ' a u32 > > ,
419
+ // Date to retrieve all tasks that were enqueued before it.
420
+ #[ serde(
421
+ skip_serializing_if = "Option::is_none" ,
422
+ serialize_with = "time::serde::rfc3339::option::serialize"
423
+ ) ]
424
+ pub before_enqueued_at : Option < OffsetDateTime > ,
425
+ // Date to retrieve all tasks that were enqueued after it.
426
+ #[ serde(
427
+ skip_serializing_if = "Option::is_none" ,
428
+ serialize_with = "time::serde::rfc3339::option::serialize"
429
+ ) ]
430
+ pub after_enqueued_at : Option < OffsetDateTime > ,
431
+ // Date to retrieve all tasks that were started before it.
432
+ #[ serde(
433
+ skip_serializing_if = "Option::is_none" ,
434
+ serialize_with = "time::serde::rfc3339::option::serialize"
435
+ ) ]
436
+ pub before_started_at : Option < OffsetDateTime > ,
437
+ // Date to retrieve all tasks that were started after it.
438
+ #[ serde(
439
+ skip_serializing_if = "Option::is_none" ,
440
+ serialize_with = "time::serde::rfc3339::option::serialize"
441
+ ) ]
442
+ pub after_started_at : Option < OffsetDateTime > ,
443
+ // Date to retrieve all tasks that were finished before it.
444
+ #[ serde(
445
+ skip_serializing_if = "Option::is_none" ,
446
+ serialize_with = "time::serde::rfc3339::option::serialize"
447
+ ) ]
448
+ pub before_finished_at : Option < OffsetDateTime > ,
449
+ // Date to retrieve all tasks that were finished after it.
450
+ #[ serde(
451
+ skip_serializing_if = "Option::is_none" ,
452
+ serialize_with = "time::serde::rfc3339::option::serialize"
453
+ ) ]
454
+ pub after_finished_at : Option < OffsetDateTime > ,
416
455
// Maximum number of tasks to return
417
456
#[ serde( skip_serializing_if = "Option::is_none" ) ]
418
457
pub limit : Option < u32 > ,
@@ -426,32 +465,88 @@ impl<'a> TasksQuery<'a> {
426
465
pub fn new ( client : & ' a Client ) -> TasksQuery < ' a > {
427
466
TasksQuery {
428
467
client,
429
- index_uid : None ,
430
- status : None ,
431
- task_type : None ,
468
+ index_uids : None ,
469
+ statuses : None ,
470
+ task_types : None ,
432
471
limit : None ,
433
472
from : None ,
473
+ uids : None ,
474
+ before_enqueued_at : None ,
475
+ after_enqueued_at : None ,
476
+ before_started_at : None ,
477
+ after_started_at : None ,
478
+ before_finished_at : None ,
479
+ after_finished_at : None ,
434
480
}
435
481
}
436
- pub fn with_index_uid < ' b > (
482
+ pub fn with_index_uids < ' b > (
483
+ & ' b mut self ,
484
+ index_uids : impl IntoIterator < Item = & ' a str > ,
485
+ ) -> & ' b mut TasksQuery < ' a > {
486
+ self . index_uids = Some ( index_uids. into_iter ( ) . collect ( ) ) ;
487
+ self
488
+ }
489
+ pub fn with_statuses < ' b > (
490
+ & ' b mut self ,
491
+ statuses : impl IntoIterator < Item = & ' a str > ,
492
+ ) -> & ' b mut TasksQuery < ' a > {
493
+ self . statuses = Some ( statuses. into_iter ( ) . collect ( ) ) ;
494
+ self
495
+ }
496
+ pub fn with_types < ' b > (
497
+ & ' b mut self ,
498
+ task_types : impl IntoIterator < Item = & ' a str > ,
499
+ ) -> & ' b mut TasksQuery < ' a > {
500
+ self . task_types = Some ( task_types. into_iter ( ) . collect ( ) ) ;
501
+ self
502
+ }
503
+ pub fn with_uids < ' b > (
504
+ & ' b mut self ,
505
+ uids : impl IntoIterator < Item = & ' a u32 > ,
506
+ ) -> & ' b mut TasksQuery < ' a > {
507
+ self . uids = Some ( uids. into_iter ( ) . collect ( ) ) ;
508
+ self
509
+ }
510
+ pub fn with_before_enqueued_at < ' b > (
437
511
& ' b mut self ,
438
- index_uid : impl IntoIterator < Item = & ' a str > ,
512
+ before_enqueued_at : & ' a OffsetDateTime ,
439
513
) -> & ' b mut TasksQuery < ' a > {
440
- self . index_uid = Some ( index_uid . into_iter ( ) . collect ( ) ) ;
514
+ self . before_enqueued_at = Some ( * before_enqueued_at ) ;
441
515
self
442
516
}
443
- pub fn with_status < ' b > (
517
+ pub fn with_after_enqueued_at < ' b > (
444
518
& ' b mut self ,
445
- status : impl IntoIterator < Item = & ' a str > ,
519
+ after_enqueued_at : & ' a OffsetDateTime ,
446
520
) -> & ' b mut TasksQuery < ' a > {
447
- self . status = Some ( status . into_iter ( ) . collect ( ) ) ;
521
+ self . after_enqueued_at = Some ( * after_enqueued_at ) ;
448
522
self
449
523
}
450
- pub fn with_type < ' b > (
524
+ pub fn with_before_started_at < ' b > (
451
525
& ' b mut self ,
452
- task_type : impl IntoIterator < Item = & ' a str > ,
526
+ before_started_at : & ' a OffsetDateTime ,
453
527
) -> & ' b mut TasksQuery < ' a > {
454
- self . task_type = Some ( task_type. into_iter ( ) . collect ( ) ) ;
528
+ self . before_started_at = Some ( * before_started_at) ;
529
+ self
530
+ }
531
+ pub fn with_after_started_at < ' b > (
532
+ & ' b mut self ,
533
+ after_started_at : & ' a OffsetDateTime ,
534
+ ) -> & ' b mut TasksQuery < ' a > {
535
+ self . after_started_at = Some ( * after_started_at) ;
536
+ self
537
+ }
538
+ pub fn with_before_finished_at < ' b > (
539
+ & ' b mut self ,
540
+ before_finished_at : & ' a OffsetDateTime ,
541
+ ) -> & ' b mut TasksQuery < ' a > {
542
+ self . before_finished_at = Some ( * before_finished_at) ;
543
+ self
544
+ }
545
+ pub fn with_after_finished_at < ' b > (
546
+ & ' b mut self ,
547
+ after_finished_at : & ' a OffsetDateTime ,
548
+ ) -> & ' b mut TasksQuery < ' a > {
549
+ self . after_finished_at = Some ( * after_finished_at) ;
455
550
self
456
551
}
457
552
pub fn with_limit < ' b > ( & ' b mut self , limit : u32 ) -> & ' b mut TasksQuery < ' a > {
@@ -640,17 +735,81 @@ mod test {
640
735
let mock_server_url = & mockito:: server_url ( ) ;
641
736
let client = Client :: new ( mock_server_url, "masterKey" ) ;
642
737
let path =
643
- "/tasks?indexUid =movies,test&status =equeued&type =documentDeletion&limit=0&from=1" ;
738
+ "/tasks?indexUids =movies,test&statuses =equeued&types =documentDeletion&uids=1 &limit=0&from=1" ;
644
739
645
740
let mock_res = mock ( "GET" , path) . with_status ( 200 ) . create ( ) ;
646
741
647
742
let mut query = TasksQuery :: new ( & client) ;
648
743
query
649
- . with_index_uid ( [ "movies" , "test" ] )
650
- . with_status ( [ "equeued" ] )
651
- . with_type ( [ "documentDeletion" ] )
744
+ . with_index_uids ( [ "movies" , "test" ] )
745
+ . with_statuses ( [ "equeued" ] )
746
+ . with_types ( [ "documentDeletion" ] )
652
747
. with_from ( 1 )
653
- . with_limit ( 0 ) ;
748
+ . with_limit ( 0 )
749
+ . with_uids ( [ & 1 ] ) ;
750
+
751
+ let _ = client. get_tasks_with ( & query) . await ;
752
+
753
+ mock_res. assert ( ) ;
754
+ Ok ( ( ) )
755
+ }
756
+
757
+ #[ meilisearch_test]
758
+ async fn test_get_tasks_with_date_params ( ) -> Result < ( ) , Error > {
759
+ let mock_server_url = & mockito:: server_url ( ) ;
760
+ let client = Client :: new ( mock_server_url, "masterKey" ) ;
761
+ let path = "/tasks?\
762
+ beforeEnqueuedAt=2022-02-03T13%3A02%3A38.369634Z\
763
+ &afterEnqueuedAt=2023-02-03T13%3A02%3A38.369634Z\
764
+ &beforeStartedAt=2024-02-03T13%3A02%3A38.369634Z\
765
+ &afterStartedAt=2025-02-03T13%3A02%3A38.369634Z\
766
+ &beforeFinishedAt=2026-02-03T13%3A02%3A38.369634Z\
767
+ &afterFinishedAt=2027-02-03T13%3A02%3A38.369634Z";
768
+
769
+ let mock_res = mock ( "GET" , path) . with_status ( 200 ) . create ( ) ;
770
+
771
+ let before_enqueued_at = OffsetDateTime :: parse (
772
+ "2022-02-03T13:02:38.369634Z" ,
773
+ & :: time:: format_description:: well_known:: Rfc3339 ,
774
+ )
775
+ . unwrap ( ) ;
776
+ let after_enqueued_at = OffsetDateTime :: parse (
777
+ "2023-02-03T13:02:38.369634Z" ,
778
+ & :: time:: format_description:: well_known:: Rfc3339 ,
779
+ )
780
+ . unwrap ( ) ;
781
+ let before_started_at = OffsetDateTime :: parse (
782
+ "2024-02-03T13:02:38.369634Z" ,
783
+ & :: time:: format_description:: well_known:: Rfc3339 ,
784
+ )
785
+ . unwrap ( ) ;
786
+
787
+ let after_started_at = OffsetDateTime :: parse (
788
+ "2025-02-03T13:02:38.369634Z" ,
789
+ & :: time:: format_description:: well_known:: Rfc3339 ,
790
+ )
791
+ . unwrap ( ) ;
792
+
793
+ let before_finished_at = OffsetDateTime :: parse (
794
+ "2026-02-03T13:02:38.369634Z" ,
795
+ & :: time:: format_description:: well_known:: Rfc3339 ,
796
+ )
797
+ . unwrap ( ) ;
798
+
799
+ let after_finished_at = OffsetDateTime :: parse (
800
+ "2027-02-03T13:02:38.369634Z" ,
801
+ & :: time:: format_description:: well_known:: Rfc3339 ,
802
+ )
803
+ . unwrap ( ) ;
804
+
805
+ let mut query = TasksQuery :: new ( & client) ;
806
+ query
807
+ . with_before_enqueued_at ( & before_enqueued_at)
808
+ . with_after_enqueued_at ( & after_enqueued_at)
809
+ . with_before_started_at ( & before_started_at)
810
+ . with_after_started_at ( & after_started_at)
811
+ . with_before_finished_at ( & before_finished_at)
812
+ . with_after_finished_at ( & after_finished_at) ;
654
813
655
814
let _ = client. get_tasks_with ( & query) . await ;
656
815
@@ -662,15 +821,15 @@ mod test {
662
821
async fn test_get_tasks_on_struct_with_params ( ) -> Result < ( ) , Error > {
663
822
let mock_server_url = & mockito:: server_url ( ) ;
664
823
let client = Client :: new ( mock_server_url, "masterKey" ) ;
665
- let path = "/tasks?indexUid =movies,test&status =equeued&type =documentDeletion" ;
824
+ let path = "/tasks?indexUids =movies,test&statuses =equeued&types =documentDeletion" ;
666
825
667
826
let mock_res = mock ( "GET" , path) . with_status ( 200 ) . create ( ) ;
668
827
669
828
let mut query = TasksQuery :: new ( & client) ;
670
829
let _ = query
671
- . with_index_uid ( [ "movies" , "test" ] )
672
- . with_status ( [ "equeued" ] )
673
- . with_type ( [ "documentDeletion" ] )
830
+ . with_index_uids ( [ "movies" , "test" ] )
831
+ . with_statuses ( [ "equeued" ] )
832
+ . with_types ( [ "documentDeletion" ] )
674
833
. execute ( )
675
834
. await ;
676
835
@@ -680,9 +839,9 @@ mod test {
680
839
}
681
840
682
841
#[ meilisearch_test]
683
- async fn test_get_tasks_with_none_existant_index_uid ( client : Client ) -> Result < ( ) , Error > {
842
+ async fn test_get_tasks_with_none_existant_index_uids ( client : Client ) -> Result < ( ) , Error > {
684
843
let mut query = TasksQuery :: new ( & client) ;
685
- query. with_index_uid ( [ "no_name" ] ) ;
844
+ query. with_index_uids ( [ "no_name" ] ) ;
686
845
let tasks = client. get_tasks_with ( & query) . await . unwrap ( ) ;
687
846
688
847
assert_eq ! ( tasks. results. len( ) , 0 ) ;
@@ -692,7 +851,7 @@ mod test {
692
851
#[ meilisearch_test]
693
852
async fn test_get_tasks_with_execute ( client : Client ) -> Result < ( ) , Error > {
694
853
let tasks = TasksQuery :: new ( & client)
695
- . with_index_uid ( [ "no_name" ] )
854
+ . with_index_uids ( [ "no_name" ] )
696
855
. execute ( )
697
856
. await
698
857
. unwrap ( ) ;
0 commit comments