Skip to content

Commit 283d25b

Browse files
committed
Introduce a skip-batches argument
1 parent 040913b commit 283d25b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/main.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ struct Opt {
5050
/// The size of the batches sent to Meilisearch.
5151
#[structopt(long, default_value = "20 MiB")]
5252
batch_size: Byte,
53+
54+
/// The number of batches to skip. Useful when the upload stopped for some reason.
55+
#[structopt(long)]
56+
skip_batches: Option<u64>,
5357
}
5458

5559
fn send_data(
@@ -122,19 +126,25 @@ fn main() -> anyhow::Result<()> {
122126

123127
match mime {
124128
Mime::Json => {
125-
let data = fs::read_to_string(file)?;
126-
send_data(&opt, &agent, &pb, &mime, data.as_bytes())?;
129+
if opt.skip_batches.zip(pb.length()).map_or(true, |(s, l)| s > l) {
130+
let data = fs::read_to_string(file)?;
131+
send_data(&opt, &agent, &pb, &mime, data.as_bytes())?;
132+
}
127133
pb.inc(1);
128134
}
129135
Mime::NdJson => {
130136
for chunk in nd_json::NdJsonChunker::new(file, size) {
131-
send_data(&opt, &agent, &pb, &mime, &chunk)?;
137+
if opt.skip_batches.zip(pb.length()).map_or(true, |(s, l)| s > l) {
138+
send_data(&opt, &agent, &pb, &mime, &chunk)?;
139+
}
132140
pb.inc(1);
133141
}
134142
}
135143
Mime::Csv => {
136144
for chunk in csv::CsvChunker::new(file, size) {
137-
send_data(&opt, &agent, &pb, &mime, &chunk)?;
145+
if opt.skip_batches.zip(pb.length()).map_or(true, |(s, l)| s > l) {
146+
send_data(&opt, &agent, &pb, &mime, &chunk)?;
147+
}
138148
pb.inc(1);
139149
}
140150
}

0 commit comments

Comments
 (0)