11use serde:: { Deserialize , Deserializer , Serialize } ;
2+ use serde_json:: { Map , Value } ;
23use std:: time:: Duration ;
34use time:: OffsetDateTime ;
45
@@ -157,6 +158,9 @@ pub struct SucceededTask {
157158 pub canceled_by : Option < usize > ,
158159 pub index_uid : Option < String > ,
159160 pub error : Option < MeilisearchError > ,
161+ /// Remotes object returned by the server for this task (present since Meilisearch 1.19)
162+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
163+ pub remotes : Option < Map < String , Value > > ,
160164 #[ serde( flatten) ]
161165 pub update_type : TaskType ,
162166 pub uid : u32 ,
@@ -174,6 +178,9 @@ pub struct EnqueuedTask {
174178 #[ serde( with = "time::serde::rfc3339" ) ]
175179 pub enqueued_at : OffsetDateTime ,
176180 pub index_uid : Option < String > ,
181+ /// Remotes object returned by the server for this enqueued task
182+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
183+ pub remotes : Option < Map < String , Value > > ,
177184 #[ serde( flatten) ]
178185 pub update_type : TaskType ,
179186 pub uid : u32 ,
@@ -193,6 +200,9 @@ pub struct ProcessingTask {
193200 #[ serde( with = "time::serde::rfc3339" ) ]
194201 pub started_at : OffsetDateTime ,
195202 pub index_uid : Option < String > ,
203+ /// Remotes object returned by the server for this processing task
204+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
205+ pub remotes : Option < Map < String , Value > > ,
196206 #[ serde( flatten) ]
197207 pub update_type : TaskType ,
198208 pub uid : u32 ,
@@ -738,6 +748,55 @@ impl<'a, Http: HttpClient> TasksQuery<'a, TasksPaginationFilters, Http> {
738748
739749#[ cfg( test) ]
740750mod test {
751+ use super :: * ;
752+
753+ #[ test]
754+ fn test_deserialize_enqueued_task_with_remotes ( ) {
755+ let json = r#"{
756+ "enqueuedAt": "2022-02-03T13:02:38.369634Z",
757+ "indexUid": "movies",
758+ "status": "enqueued",
759+ "type": "indexUpdate",
760+ "uid": 12,
761+ "remotes": { "ms-00": { "status": "ok" } }
762+ }"# ;
763+ let task: Task = serde_json:: from_str ( json) . unwrap ( ) ;
764+ match task {
765+ Task :: Enqueued { content } => {
766+ let remotes = content. remotes . expect ( "remotes should be present" ) ;
767+ assert ! ( remotes. contains_key( "ms-00" ) ) ;
768+ }
769+ _ => panic ! ( "expected enqueued task" ) ,
770+ }
771+ }
772+
773+ #[ test]
774+ fn test_deserialize_processing_task_with_remotes ( ) {
775+ let json = r#"{
776+ "details": {
777+ "indexedDocuments": null,
778+ "receivedDocuments": 10
779+ },
780+ "duration": null,
781+ "enqueuedAt": "2022-02-03T15:17:02.801341Z",
782+ "finishedAt": null,
783+ "indexUid": "movies",
784+ "startedAt": "2022-02-03T15:17:02.812338Z",
785+ "status": "processing",
786+ "type": "documentAdditionOrUpdate",
787+ "uid": 14,
788+ "remotes": { "ms-00": { "status": "ok" } }
789+ }"# ;
790+ let task: Task = serde_json:: from_str ( json) . unwrap ( ) ;
791+ match task {
792+ Task :: Processing { content } => {
793+ let remotes = content. remotes . expect ( "remotes should be present" ) ;
794+ assert ! ( remotes. contains_key( "ms-00" ) ) ;
795+ }
796+ _ => panic ! ( "expected processing task" ) ,
797+ }
798+ }
799+
741800 use super :: * ;
742801 use crate :: {
743802 client:: * ,
@@ -782,8 +841,7 @@ mod test {
782841 enqueued_at,
783842 index_uid: Some ( index_uid) ,
784843 update_type: TaskType :: DocumentAdditionOrUpdate { details: None } ,
785- uid: 12 ,
786- }
844+ uid: 12 , .. }
787845 }
788846 if enqueued_at == datetime && index_uid == "meili" ) ) ;
789847
0 commit comments