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,54 @@ impl<'a, Http: HttpClient> TasksQuery<'a, TasksPaginationFilters, Http> {
738748
739749#[ cfg( test) ]
740750mod test {
751+
752+ #[ test]
753+ fn test_deserialize_enqueued_task_with_remotes ( ) {
754+ let json = r#"{
755+ "enqueuedAt": "2022-02-03T13:02:38.369634Z",
756+ "indexUid": "movies",
757+ "status": "enqueued",
758+ "type": "indexUpdate",
759+ "uid": 12,
760+ "remotes": { "ms-00": { "status": "ok" } }
761+ }"# ;
762+ let task: Task = serde_json:: from_str ( json) . unwrap ( ) ;
763+ match task {
764+ Task :: Enqueued { content } => {
765+ let remotes = content. remotes . expect ( "remotes should be present" ) ;
766+ assert ! ( remotes. contains_key( "ms-00" ) ) ;
767+ }
768+ _ => panic ! ( "expected enqueued task" ) ,
769+ }
770+ }
771+
772+ #[ test]
773+ fn test_deserialize_processing_task_with_remotes ( ) {
774+ let json = r#"{
775+ "details": {
776+ "indexedDocuments": null,
777+ "receivedDocuments": 10
778+ },
779+ "duration": null,
780+ "enqueuedAt": "2022-02-03T15:17:02.801341Z",
781+ "finishedAt": null,
782+ "indexUid": "movies",
783+ "startedAt": "2022-02-03T15:17:02.812338Z",
784+ "status": "processing",
785+ "type": "documentAdditionOrUpdate",
786+ "uid": 14,
787+ "remotes": { "ms-00": { "status": "ok" } }
788+ }"# ;
789+ let task: Task = serde_json:: from_str ( json) . unwrap ( ) ;
790+ match task {
791+ Task :: Processing { content } => {
792+ let remotes = content. remotes . expect ( "remotes should be present" ) ;
793+ assert ! ( remotes. contains_key( "ms-00" ) ) ;
794+ }
795+ _ => panic ! ( "expected processing task" ) ,
796+ }
797+ }
798+
741799 use super :: * ;
742800 use crate :: {
743801 client:: * ,
@@ -782,8 +840,7 @@ mod test {
782840 enqueued_at,
783841 index_uid: Some ( index_uid) ,
784842 update_type: TaskType :: DocumentAdditionOrUpdate { details: None } ,
785- uid: 12 ,
786- }
843+ uid: 12 , .. }
787844 }
788845 if enqueued_at == datetime && index_uid == "meili" ) ) ;
789846
0 commit comments