lifecycle worker: avoid building chrono's serde feature

This commit is contained in:
Alex 2023-08-30 23:46:15 +02:00
parent f0a395e2e5
commit 01c327a07a
2 changed files with 11 additions and 11 deletions

View file

@ -23,7 +23,7 @@ garage_util.workspace = true
async-trait = "0.1.7" async-trait = "0.1.7"
arc-swap = "1.0" arc-swap = "1.0"
blake2 = "0.10" blake2 = "0.10"
chrono = { version = "0.4", features = ["serde"] } chrono = "0.4"
err-derive = "0.3" err-derive = "0.3"
hex = "0.4" hex = "0.4"
base64 = "0.21" base64 = "0.21"

View file

@ -19,12 +19,11 @@ use crate::s3::object_table::*;
use crate::garage::Garage; use crate::garage::Garage;
mod v090 { mod v090 {
use chrono::naive::NaiveDate;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Default, Clone, Copy)] #[derive(Serialize, Deserialize, Default, Clone)]
pub struct LifecycleWorkerPersisted { pub struct LifecycleWorkerPersisted {
pub last_completed: Option<NaiveDate>, pub last_completed: Option<String>,
} }
impl garage_util::migrate::InitialFormat for LifecycleWorkerPersisted { impl garage_util::migrate::InitialFormat for LifecycleWorkerPersisted {
@ -65,18 +64,19 @@ pub fn register_bg_vars(
vars: &mut vars::BgVars, vars: &mut vars::BgVars,
) { ) {
vars.register_ro(persister, "lifecycle-last-completed", |p| { vars.register_ro(persister, "lifecycle-last-completed", |p| {
p.get_with(|x| { p.get_with(|x| x.last_completed.clone().unwrap_or("never".to_string()))
x.last_completed
.map(|date| date.to_string())
.unwrap_or("never".to_string())
})
}); });
} }
impl LifecycleWorker { impl LifecycleWorker {
pub fn new(garage: Arc<Garage>, persister: PersisterShared<LifecycleWorkerPersisted>) -> Self { pub fn new(garage: Arc<Garage>, persister: PersisterShared<LifecycleWorkerPersisted>) -> Self {
let today = today(); let today = today();
let state = match persister.get_with(|x| x.last_completed) { let last_completed = persister.get_with(|x| {
x.last_completed
.as_deref()
.and_then(|x| x.parse::<NaiveDate>().ok())
});
let state = match last_completed {
Some(d) if d >= today => State::Completed(d), Some(d) if d >= today => State::Completed(d),
_ => State::Running { _ => State::Running {
date: today, date: today,
@ -162,7 +162,7 @@ impl Worker for LifecycleWorker {
None => { None => {
info!("Lifecycle worker finished for {}, objects expired: {}, mpu aborted: {}", date, *objects_expired, *mpu_aborted); info!("Lifecycle worker finished for {}, objects expired: {}, mpu aborted: {}", date, *objects_expired, *mpu_aborted);
self.persister self.persister
.set_with(|x| x.last_completed = Some(*date))?; .set_with(|x| x.last_completed = Some(date.to_string()))?;
self.state = State::Completed(*date); self.state = State::Completed(*date);
return Ok(WorkerState::Idle); return Ok(WorkerState::Idle);
} }