pub fn save<P: AsRef<Path> + Debug>(
        &mut self,
        snapshot_file: P,
        snapshot_retention: u64,
    ) -> AppResult<()> {
        let seconds_from_epoch = from_epoch_secs()?;

        // first delete tags having run before retention
        debug!("checking retention time for snapshot");
        for logfile in self.snapshot.values_mut() {
            let run_data = logfile.rundata_mut();
            run_data.retain(|_, v| seconds_from_epoch - v.last_run_secs < snapshot_retention);
        }

        // because of before deletion, some logfiles might not include run_data anymore. So no need to keep them
        self.snapshot.retain(|_, v| !v.run_data.is_empty());

        // then just saves this file.
        let json_file = File::create(&snapshot_file)
            .map_err(|e| context!(e, "unable create snapshot file: {:?}", snapshot_file))?;
        serde_json::to_writer_pretty(json_file, self)
            .map_err(|e| context!(e, "to_writer_pretty() error",))?;

        Ok(())
    }
/// Serialize snapshot data to a JSON file.
Serialize snapshot data to a JSON file.
Serialize snapshot data to a JSON file .
pub fn save<P: AsRef<Path> + Debug>(
        &mut self,
        snapshot_file: P,
        snapshot_retention: u64,
    ) -> AppResult<()> {
        let seconds_from_epoch = from_epoch_secs()?;
        // first delete tags having run before retention
        debug!("checking retention time for snapshot");
        for logfile in self.snapshot.values_mut() {
            let run_data = logfile.rundata_mut();
            run_data.retain(|_, v| seconds_from_epoch - v.last_run_secs < snapshot_retention);
        }
        // because of before deletion, some logfiles might not include run_data anymore. So no need to keep them
        self.snapshot.retain(|_, v| !v.run_data.is_empty());
        // then just saves this file.
        let json_file = File::create(&snapshot_file)
            .map_err(|e| context!(e, "unable create snapshot file: {:?}", snapshot_file))?;
        serde_json::to_writer_pretty(json_file, self)
            .map_err(|e| context!(e, "to_writer_pretty() error",))?;
        Ok(())
    }
pub fn save < P : AsRef < Path > + Debug > ( & mut self , snapshot_file : P , snapshot_retention : u64 , ) -> AppResult < ( ) > { let seconds_from_epoch = from_epoch_secs ( ) ? ; // first delete tags having run before retention debug ! ( " " ) ; for logfile in self . snapshot . values_mut ( ) { let run_data = logfile . rundata_mut ( ) ; run_data . retain ( | _ , v | seconds_from_epoch - v . last_run_secs < snapshot_retention ) ; } // because of before deletion, some logfiles might not include run_data anymore. So no need to keep them self . snapshot . retain ( | _ , v | ! v . run_data . is_empty ( ) ) ; // then just saves this file. let json_file = File :: create ( & snapshot_file ) . map_err ( | e | context ! ( e " " snapshot_file ) ) ? ; serde_json :: to_writer_pretty ( json_file , self ) . map_err ( | e | context ! ( e " " ) ) ? ; Ok ( ( ) ) }
Serialize snapshot data to a JSON file.
Serialize snapshot data to a JSON file .
&mut self
snapshot_file
P
snapshot_retention
u64
&mut self
snapshot_file
P
snapshot_retention
u64