@@ -130,6 +130,14 @@ pub struct KeepOptions {
130
130
#[ cfg_attr( feature = "merge" , merge( strategy = conflate:: option:: overwrite_none) ) ]
131
131
pub keep_last : Option < i32 > ,
132
132
133
+ /// Keep the last N minutely snapshots (N == -1: keep all minutely snapshots)
134
+ #[ cfg_attr(
135
+ feature = "clap" ,
136
+ clap( long, short = 'M' , value_name = "N" , allow_hyphen_values = true , value_parser = clap:: value_parser!( i32 ) . range( -1 ..) )
137
+ ) ]
138
+ #[ cfg_attr( feature = "merge" , merge( strategy = conflate:: option:: overwrite_none) ) ]
139
+ pub keep_minutely : Option < i32 > ,
140
+
133
141
/// Keep the last N hourly snapshots (N == -1: keep all hourly snapshots)
134
142
#[ cfg_attr(
135
143
feature = "clap" ,
@@ -192,6 +200,12 @@ pub struct KeepOptions {
192
200
#[ cfg_attr( feature = "merge" , merge( strategy = conflate:: option:: overwrite_none) ) ]
193
201
pub keep_within : Option < humantime:: Duration > ,
194
202
203
+ /// Keep minutely snapshots newer than DURATION relative to latest snapshot
204
+ #[ cfg_attr( feature = "clap" , clap( long, value_name = "DURATION" ) ) ]
205
+ #[ serde_as( as = "Option<DisplayFromStr>" ) ]
206
+ #[ cfg_attr( feature = "merge" , merge( strategy = conflate:: option:: overwrite_none) ) ]
207
+ pub keep_within_minutely : Option < humantime:: Duration > ,
208
+
195
209
/// Keep hourly snapshots newer than DURATION relative to latest snapshot
196
210
#[ cfg_attr( feature = "clap" , clap( long, value_name = "DURATION" ) ) ]
197
211
#[ serde_as( as = "Option<DisplayFromStr>" ) ]
@@ -356,12 +370,31 @@ fn equal_hour(sn1: &SnapshotFile, sn2: &SnapshotFile) -> bool {
356
370
t1. year ( ) == t2. year ( ) && t1. ordinal ( ) == t2. ordinal ( ) && t1. hour ( ) == t2. hour ( )
357
371
}
358
372
373
+ /// Evaluate the minutes of the given snapshots
374
+ ///
375
+ /// # Arguments
376
+ ///
377
+ /// * `sn1` - The first snapshot
378
+ /// * `sn2` - The second snapshot
379
+ ///
380
+ /// # Returns
381
+ ///
382
+ /// Whether the minutes of the snapshots are equal
383
+ fn equal_minute ( sn1 : & SnapshotFile , sn2 : & SnapshotFile ) -> bool {
384
+ let ( t1, t2) = ( sn1. time , sn2. time ) ;
385
+ t1. year ( ) == t2. year ( )
386
+ && t1. ordinal ( ) == t2. ordinal ( )
387
+ && t1. hour ( ) == t2. hour ( )
388
+ && t1. minute ( ) == t2. minute ( )
389
+ }
390
+
359
391
impl KeepOptions {
360
392
/// Check if `KeepOptions` are valid, i.e. if at least one keep-* option is given.
361
393
fn is_valid ( & self ) -> bool {
362
394
!self . keep_tags . is_empty ( )
363
395
|| !self . keep_ids . is_empty ( )
364
396
|| self . keep_last . is_some ( )
397
+ || self . keep_minutely . is_some ( )
365
398
|| self . keep_hourly . is_some ( )
366
399
|| self . keep_daily . is_some ( )
367
400
|| self . keep_weekly . is_some ( )
@@ -370,6 +403,7 @@ impl KeepOptions {
370
403
|| self . keep_half_yearly . is_some ( )
371
404
|| self . keep_within . is_some ( )
372
405
|| self . keep_yearly . is_some ( )
406
+ || self . keep_within_minutely . is_some ( )
373
407
|| self . keep_within_hourly . is_some ( )
374
408
|| self . keep_within_daily . is_some ( )
375
409
|| self . keep_within_weekly . is_some ( )
@@ -392,6 +426,7 @@ impl KeepOptions {
392
426
/// # Returns
393
427
///
394
428
/// The list of reasons why the snapshot should be kept
429
+ #[ allow( clippy:: too_many_lines) ]
395
430
fn matches (
396
431
& mut self ,
397
432
sn : & SnapshotFile ,
@@ -422,14 +457,21 @@ impl KeepOptions {
422
457
reason. push ( "tags" ) ;
423
458
}
424
459
425
- let keep_checks: [ MatchParameters < ' _ > ; 8 ] = [
460
+ let keep_checks: [ MatchParameters < ' _ > ; 9 ] = [
426
461
(
427
462
always_false,
428
463
& mut self . keep_last ,
429
464
"last" ,
430
465
self . keep_within ,
431
466
"within" ,
432
467
) ,
468
+ (
469
+ equal_minute,
470
+ & mut self . keep_minutely ,
471
+ "minutely" ,
472
+ self . keep_within_minutely ,
473
+ "within minutely" ,
474
+ ) ,
433
475
(
434
476
equal_hour,
435
477
& mut self . keep_hourly ,
0 commit comments