1+ use crate :: { client:: Client , errors:: Error , request:: HttpClient } ;
12use serde:: { Deserialize , Serialize } ;
3+ use std:: collections:: HashMap ;
24use time:: OffsetDateTime ;
35
4- use crate :: { client:: Client , errors:: Error , request:: HttpClient } ;
5-
66/// Types and queries for the Meilisearch Batches API.
77///
88/// See: https://www.meilisearch.com/docs/reference/api/batches
99#[ derive( Debug , Clone , Deserialize ) ]
1010#[ serde( rename_all = "camelCase" ) ]
1111pub struct Batch {
1212 /// Unique identifier of the batch.
13- pub uid : u32 ,
14- /// When the batch was enqueued.
15- #[ serde( default , with = "time::serde::rfc3339::option" ) ]
16- pub enqueued_at : Option < OffsetDateTime > ,
13+ pub uid : i64 ,
14+ /// Batch progress.
15+ pub progress : Option < BatchProgress > ,
16+ /// Batch stats.
17+ pub stats : BatchStats ,
18+ /// The total elapsed time the batch spent in the processing state, in ISO 8601 format.
19+ pub duration : Option < String > ,
1720 /// When the batch started processing.
1821 #[ serde( default , with = "time::serde::rfc3339::option" ) ]
1922 pub started_at : Option < OffsetDateTime > ,
2023 /// When the batch finished processing.
2124 #[ serde( default , with = "time::serde::rfc3339::option" ) ]
2225 pub finished_at : Option < OffsetDateTime > ,
23- /// Index uid related to this batch (if applicable).
24- #[ serde( skip_serializing_if = "Option::is_none" ) ]
25- pub index_uid : Option < String > ,
26- /// The task uids that are part of this batch.
27- #[ serde( skip_serializing_if = "Option::is_none" ) ]
28- pub task_uids : Option < Vec < u32 > > ,
2926 /// The strategy that caused the autobatcher to stop batching tasks.
30- ///
3127 /// Introduced in Meilisearch v1.15.
3228 #[ serde( skip_serializing_if = "Option::is_none" ) ]
3329 pub batch_strategy : Option < BatchStrategy > ,
3430}
3531
36- /// Reason why the autobatcher stopped batching tasks.
32+ /// Reason why the auto batcher stopped batching tasks.
3733#[ derive( Debug , Clone , Copy , PartialEq , Eq , Serialize , Deserialize ) ]
3834#[ serde( rename_all = "snake_case" ) ]
3935#[ non_exhaustive]
@@ -65,21 +61,70 @@ pub struct BatchesResults {
6561pub struct BatchesQuery < ' a , Http : HttpClient > {
6662 #[ serde( skip_serializing) ]
6763 client : & ' a Client < Http > ,
64+ ///Select batches containing the tasks with the specified uids.
65+ /// Separate multiple task uids with a comma
66+ #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
67+ uids : Vec < i64 > ,
68+ /// Filter batches by their uid. Separate multiple batch uids with a comma
69+ #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
70+ batch_uids : Vec < i64 > ,
71+ /// Select batches containing tasks affecting the specified indexes.
72+ /// Separate multiple indexUids with a comma
73+ #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
74+ index_uids : Vec < String > ,
75+ /// Select batches containing tasks with the specified status.
76+ #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
77+ statuses : Vec < Status > ,
78+ /// Select batches containing tasks with the specified type.
79+ #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
80+ types : Vec < Type > ,
6881 /// Maximum number of batches to return.
6982 #[ serde( skip_serializing_if = "Option::is_none" ) ]
7083 limit : Option < u32 > ,
7184 /// The first batch uid that should be returned.
7285 #[ serde( skip_serializing_if = "Option::is_none" ) ]
7386 from : Option < u32 > ,
87+ /// If true, returns results in the reverse order, from oldest to most recent
88+ reverse : bool ,
89+ /// Select batches containing tasks with the specified enqueuedAt field
90+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
91+ before_enqueued_at : Option < OffsetDateTime > ,
92+ /// Select batches containing tasks with the specified startedAt field
93+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
94+ before_started_at : Option < OffsetDateTime > ,
95+ /// Select batches containing tasks with the specified finishedAt field
96+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
97+ before_finished_at : Option < OffsetDateTime > ,
98+ /// Select batches containing tasks with the specified enqueuedAt field
99+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
100+ after_enqueued_at : Option < OffsetDateTime > ,
101+ /// Select batches containing tasks with the specified startedAt field
102+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
103+ after_started_at : Option < OffsetDateTime > ,
104+ /// Select batches containing tasks with the specified finishedAt field
105+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
106+ after_finished_at : Option < OffsetDateTime > ,
74107}
75108
76109impl < ' a , Http : HttpClient > BatchesQuery < ' a , Http > {
77110 #[ must_use]
78111 pub fn new ( client : & ' a Client < Http > ) -> BatchesQuery < ' a , Http > {
79112 BatchesQuery {
80113 client,
114+ uids : vec ! [ ] ,
115+ batch_uids : vec ! [ ] ,
116+ index_uids : vec ! [ ] ,
117+ statuses : vec ! [ ] ,
118+ types : vec ! [ ] ,
81119 limit : None ,
82120 from : None ,
121+ reverse : false ,
122+ before_enqueued_at : None ,
123+ before_started_at : None ,
124+ before_finished_at : None ,
125+ after_enqueued_at : None ,
126+ after_started_at : None ,
127+ after_finished_at : None ,
83128 }
84129 }
85130
@@ -95,12 +140,141 @@ impl<'a, Http: HttpClient> BatchesQuery<'a, Http> {
95140 self
96141 }
97142
143+ #[ must_use]
144+ pub fn with_uids ( & mut self , uids : Vec < i64 > ) -> & mut Self {
145+ self . uids = uids;
146+ self
147+ }
148+
149+ #[ must_use]
150+ pub fn with_batch_uids ( & mut self , batch_uids : Vec < i64 > ) -> & mut Self {
151+ self . batch_uids = batch_uids;
152+ self
153+ }
154+
155+ #[ must_use]
156+ pub fn with_index_uids ( & mut self , index_uids : Vec < String > ) -> & mut Self {
157+ self . index_uids = index_uids;
158+ self
159+ }
160+
161+ #[ must_use]
162+ pub fn with_statuses ( & mut self , statuses : Vec < Status > ) -> & mut Self {
163+ self . statuses = statuses;
164+ self
165+ }
166+
167+ #[ must_use]
168+ pub fn with_types ( & mut self , types : Vec < Type > ) -> & mut Self {
169+ self . types = types;
170+ self
171+ }
172+
173+ #[ must_use]
174+ pub fn with_reverse ( & mut self , reverse : bool ) -> & mut Self {
175+ self . reverse = reverse;
176+ self
177+ }
178+
179+ #[ must_use]
180+ pub fn with_before_enqueued_at ( & mut self , before_enqueued_at : OffsetDateTime ) -> & mut Self {
181+ self . before_enqueued_at = Some ( before_enqueued_at) ;
182+ self
183+ }
184+
185+ #[ must_use]
186+ pub fn with_before_started_at ( & mut self , before_started_at : OffsetDateTime ) -> & mut Self {
187+ self . before_started_at = Some ( before_started_at) ;
188+ self
189+ }
190+
191+ #[ must_use]
192+ pub fn with_before_finished_at ( & mut self , before_finished_at : OffsetDateTime ) -> & mut Self {
193+ self . before_finished_at = Some ( before_finished_at) ;
194+ self
195+ }
196+
197+ #[ must_use]
198+ pub fn with_after_enqueued_at ( & mut self , after_enqueued_at : OffsetDateTime ) -> & mut Self {
199+ self . after_enqueued_at = Some ( after_enqueued_at) ;
200+ self
201+ }
202+
203+ #[ must_use]
204+ pub fn with_after_started_at ( & mut self , after_started_at : OffsetDateTime ) -> & mut Self {
205+ self . after_started_at = Some ( after_started_at) ;
206+ self
207+ }
208+
209+ #[ must_use]
210+ pub fn with_after_finished_at ( & mut self , after_finished_at : OffsetDateTime ) -> & mut Self {
211+ self . after_finished_at = Some ( after_finished_at) ;
212+ self
213+ }
214+
98215 /// Execute the query and list batches.
99216 pub async fn execute ( & self ) -> Result < BatchesResults , Error > {
100217 self . client . get_batches_with ( self ) . await
101218 }
102219}
103220
221+ #[ derive( Debug , Clone , Deserialize ) ]
222+ pub struct BatchProgress {
223+ pub steps : Vec < BatchProgressStep > ,
224+ pub percentage : f64 ,
225+ }
226+
227+ #[ derive( Debug , Clone , Deserialize ) ]
228+ #[ serde( rename_all = "camelCase" ) ]
229+ pub struct BatchProgressStep {
230+ pub current_step : String ,
231+ pub finished : i32 ,
232+ pub total : i32 ,
233+ }
234+
235+ #[ derive( Debug , Clone , Deserialize ) ]
236+ #[ serde( rename_all = "camelCase" ) ]
237+ pub struct BatchStats {
238+ pub total_nb_tasks : i32 ,
239+ pub status : HashMap < Status , i32 > ,
240+ pub types : HashMap < Type , i32 > ,
241+ pub indexed_uids : HashMap < String , i32 > ,
242+ pub progress_trace : HashMap < String , String > ,
243+ pub write_channel_congestion : HashMap < String , String > ,
244+ pub internal_database_sizes : HashMap < String , String > ,
245+ }
246+
247+ #[ derive( Debug , Clone , Deserialize , Serialize , Hash , PartialEq , Eq ) ]
248+ #[ serde( rename_all = "camelCase" ) ]
249+ pub enum Status {
250+ Enqueued ,
251+ Processing ,
252+ Succeeded ,
253+ Failed ,
254+ Canceled ,
255+ }
256+
257+ #[ derive( Debug , Clone , Deserialize , Serialize , Hash , PartialEq , Eq ) ]
258+ #[ serde( rename_all = "camelCase" ) ]
259+ pub enum Type {
260+ DocumentAdditionOrUpdate ,
261+ DocumentEdition ,
262+ DocumentDeletion ,
263+ SettingsUpdate ,
264+ IndexCreation ,
265+ IndexDeletion ,
266+ IndexUpdate ,
267+ IndexSwap ,
268+ TaskCancellation ,
269+ TaskDeletion ,
270+ DumpCreation ,
271+ SnapshotCreation ,
272+ Export ,
273+ UpgradeDatabase ,
274+ IndexCompaction ,
275+ NetworkTopologyChange ,
276+ }
277+
104278#[ cfg( test) ]
105279mod tests {
106280 use crate :: batches:: BatchStrategy ;
0 commit comments