Crono expression parser fix (#1682)

This commit is contained in:
Sebastiano Tocci 2023-06-03 05:07:29 +02:00 committed by GitHub
parent d3fda4210f
commit 1c1b54df86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 8 deletions

View file

@ -102,6 +102,10 @@ origin = "https://idm.example.com:8443"
# schedule = "00 22 * * *" # schedule = "00 22 * * *"
# four times a day at 3 minutes past the hour, every 6th hours # four times a day at 3 minutes past the hour, every 6th hours
# schedule = "03 */6 * * *" # schedule = "03 */6 * * *"
# We also support non standard cron syntax, with the following format:
# sec min hour day of month month day of week year
# (it's very similar to the standard cron syntax, it just allows to specify the seconds
# at the beginning and the year at the end)
# Number of backups to keep (default 7) # Number of backups to keep (default 7)
# versions = 7 # versions = 7
# #

View file

@ -56,17 +56,33 @@ impl IntervalActor {
#[allow(clippy::result_unit_err)] #[allow(clippy::result_unit_err)]
pub fn start_online_backup( pub fn start_online_backup(
server: &'static QueryServerReadV1, server: &'static QueryServerReadV1,
cfg: &OnlineBackup, online_backup_config: &OnlineBackup,
mut rx: broadcast::Receiver<CoreAction>, mut rx: broadcast::Receiver<CoreAction>,
) -> Result<tokio::task::JoinHandle<()>, ()> { ) -> Result<tokio::task::JoinHandle<()>, ()> {
let outpath = cfg.path.to_owned(); let outpath = online_backup_config.path.to_owned();
let versions = cfg.versions; let versions = online_backup_config.versions;
let crono_expr = online_backup_config.schedule.as_str().to_string();
let mut crono_expr_values = crono_expr.split_ascii_whitespace().collect::<Vec<&str>>();
let chrono_expr_uses_standard_syntax = crono_expr_values.len() == 5;
if chrono_expr_uses_standard_syntax {
// we add a 0 element at the beginning to simulate the standard crono syntax which always runs
// commands at seconds 00
crono_expr_values.insert(0, "0");
crono_expr_values.push("*");
}
let crono_expr_schedule = crono_expr_values.join(" ");
if chrono_expr_uses_standard_syntax {
info!(
"Provided online backup schedule is: {}, now being transformed to: {}",
crono_expr, crono_expr_schedule
);
}
// Cron expression handling // Cron expression handling
let cron_expr = Schedule::from_str(cfg.schedule.as_str()).map_err(|e| { let cron_expr = Schedule::from_str(crono_expr_schedule.as_str()).map_err(|e| {
error!("Online backup schedule parse error: {}", e); error!("Online backup schedule parse error: {}", e);
error!("valid formats are:"); error!("valid formats are:");
error!("sec min hour day of month month day of week year"); error!("sec min hour day of month month day of week year");
error!("min hour day of month month day of week");
error!("@hourly | @daily | @weekly"); error!("@hourly | @daily | @weekly");
})?; })?;

View file

@ -739,9 +739,12 @@ pub async fn create_server_core(
let interval_handle = IntervalActor::start(server_write_ref, broadcast_tx.subscribe()); let interval_handle = IntervalActor::start(server_write_ref, broadcast_tx.subscribe());
// Setup timed events associated to the read thread // Setup timed events associated to the read thread
let maybe_backup_handle = match &config.online_backup { let maybe_backup_handle = match &config.online_backup {
Some(cfg) => { Some(online_backup_config) => {
let handle = let handle = IntervalActor::start_online_backup(
IntervalActor::start_online_backup(server_read_ref, cfg, broadcast_tx.subscribe())?; server_read_ref,
online_backup_config,
broadcast_tx.subscribe(),
)?;
Some(handle) Some(handle)
} }
None => { None => {