refactor time functions to tools

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Dominik Csapak
2020-06-10 12:02:56 +02:00
committed by Wolfgang Bumiller
parent 3d68536fc2
commit e693818afc
7 changed files with 39 additions and 33 deletions

View File

@ -12,7 +12,7 @@ use proxmox::api::RpcEnvironmentType;
use proxmox_backup::configdir;
use proxmox_backup::buildcfg;
use proxmox_backup::server;
use proxmox_backup::tools::daemon;
use proxmox_backup::tools::{daemon, epoch_now, epoch_now_u64};
use proxmox_backup::server::{ApiConfig, rest::*};
use proxmox_backup::auth_helpers::*;
use proxmox_backup::tools::disks::{ DiskManage, zfs_pool_stats };
@ -134,10 +134,10 @@ fn start_task_scheduler() {
tokio::spawn(task.map(|_| ()));
}
use std::time:: {Instant, Duration, SystemTime, UNIX_EPOCH};
use std::time:: {Instant, Duration};
fn next_minute() -> Result<Instant, Error> {
let epoch_now = SystemTime::now().duration_since(UNIX_EPOCH)?;
let epoch_now = epoch_now()?;
let epoch_next = Duration::from_secs((epoch_now.as_secs()/60 + 1)*60);
Ok(Instant::now() + epoch_next - epoch_now)
}
@ -296,8 +296,9 @@ async fn schedule_datastore_garbage_collection() {
continue;
}
};
let now = match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(epoch_now) => epoch_now.as_secs() as i64,
let now = match epoch_now_u64() {
Ok(epoch_now) => epoch_now as i64,
Err(err) => {
eprintln!("query system time failed - {}", err);
continue;
@ -407,8 +408,8 @@ async fn schedule_datastore_prune() {
}
};
let now = match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(epoch_now) => epoch_now.as_secs() as i64,
let now = match epoch_now_u64() {
Ok(epoch_now) => epoch_now as i64,
Err(err) => {
eprintln!("query system time failed - {}", err);
continue;
@ -532,8 +533,8 @@ async fn schedule_datastore_sync_jobs() {
}
};
let now = match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(epoch_now) => epoch_now.as_secs() as i64,
let now = match epoch_now_u64() {
Ok(epoch_now) => epoch_now as i64,
Err(err) => {
eprintln!("query system time failed - {}", err);
continue;