From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 4/4] GC status: reduce code duplication
Date: Mon, 22 Apr 2024 13:38:34 +0200 [thread overview]
Message-ID: <20240422113834.842169-5-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20240422113834.842169-1-f.gruenbichler@proxmox.com>
the schedule handling is the same whether there was a last run or not, so let's
do it once and not twice. the duration can be stored right away, instead of
using an intermediate variable.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
src/api2/admin/datastore.rs | 84 ++++++++++++++-----------------------
1 file changed, 31 insertions(+), 53 deletions(-)
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index e7a823b5..3ea17499 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -1248,67 +1248,45 @@ pub fn garbage_collection_status(
.map_err(|err| log::error!("could not open GC statefile for {store}: {err}"))
.ok();
- match status_in_memory.upid {
- Some(ref upid) => {
- let mut computed_schedule: JobScheduleStatus = JobScheduleStatus::default();
- let mut duration = None;
- if let Some(state) = state_file {
- if let Ok(cs) = compute_schedule_status(&state, Some(&upid)) {
- computed_schedule = cs;
- }
- }
-
- if let Some(endtime) = computed_schedule.last_run_endtime {
- computed_schedule.next_run = info
- .schedule
- .as_ref()
- .and_then(|s| {
- s.parse::<CalendarEvent>()
- .map_err(|err| log::error!("{err}"))
- .ok()
- })
- .and_then(|e| {
- e.compute_next_event(endtime)
- .map_err(|err| log::error!("{err}"))
- .ok()
- })
- .and_then(|ne| ne);
+ let mut last = proxmox_time::epoch_i64();
- if let Ok(parsed_upid) = upid.parse::<UPID>() {
- duration = Some(endtime - parsed_upid.starttime);
- }
+ if let Some(ref upid) = status_in_memory.upid {
+ let mut computed_schedule: JobScheduleStatus = JobScheduleStatus::default();
+ if let Some(state) = state_file {
+ if let Ok(cs) = compute_schedule_status(&state, Some(&upid)) {
+ computed_schedule = cs;
}
-
- info.status = status_in_memory;
- info.next_run = computed_schedule.next_run;
- info.last_run_endtime = computed_schedule.last_run_endtime;
- info.last_run_state = computed_schedule.last_run_state;
- info.duration = duration;
}
- None => {
- if let Some(schedule) = &info.schedule {
- info.next_run = schedule
- .parse::<CalendarEvent>()
- .map_err(|err| log::error!("{err}"))
- .ok()
- .and_then(|e| {
- e.compute_next_event(proxmox_time::epoch_i64())
- .map_err(|err| log::error!("{err}"))
- .ok()
- })
- .and_then(|ne| ne);
- if let Ok(event) = schedule.parse::<CalendarEvent>() {
- if let Ok(next_event) = event.compute_next_event(proxmox_time::epoch_i64()) {
- info.next_run = next_event;
- }
- }
- } else {
- return Ok(info);
+ if let Some(endtime) = computed_schedule.last_run_endtime {
+ last = endtime;
+ if let Ok(parsed_upid) = upid.parse::<UPID>() {
+ info.duration = Some(endtime - parsed_upid.starttime);
}
}
+
+ info.next_run = computed_schedule.next_run;
+ info.last_run_endtime = computed_schedule.last_run_endtime;
+ info.last_run_state = computed_schedule.last_run_state;
}
+ info.next_run = info
+ .schedule
+ .as_ref()
+ .and_then(|s| {
+ s.parse::<CalendarEvent>()
+ .map_err(|err| log::error!("{err}"))
+ .ok()
+ })
+ .and_then(|e| {
+ e.compute_next_event(last)
+ .map_err(|err| log::error!("{err}"))
+ .ok()
+ })
+ .and_then(|ne| ne);
+
+ info.status = status_in_memory;
+
Ok(info)
}
--
2.39.2
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2024-04-22 11:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-22 11:05 [pbs-devel] [PATCH proxmox-backup 0/3] follow ups for gc job status series Dominik Csapak
2024-04-22 11:05 ` [pbs-devel] [PATCH proxmox-backup 1/3] ui: gc view: use beforedestroy for stopping the store Dominik Csapak
2024-04-22 11:05 ` [pbs-devel] [PATCH proxmox-backup 2/3] ui: prune/gc view: improve sizing & scrolling behaviour Dominik Csapak
2024-04-22 11:05 ` [pbs-devel] [PATCH proxmox-backup 3/3] ui: gc view: remove unnecessary widths in columns Dominik Csapak
2024-04-22 11:38 ` [pbs-devel] [PATCH proxmox-backup 0/4] more follow-ups Fabian Grünbichler
2024-04-22 11:38 ` [pbs-devel] [PATCH proxmox-backup 1/4] GC: flatten existing status into job status Fabian Grünbichler
2024-04-22 11:38 ` [pbs-devel] [PATCH proxmox-backup 2/4] api: merge garbage-collection-status and -job-status Fabian Grünbichler
2024-04-22 11:38 ` [pbs-devel] [PATCH proxmox-backup 3/4] ui: don't re-calculate GC duration Fabian Grünbichler
2024-04-22 11:38 ` Fabian Grünbichler [this message]
2024-04-23 12:36 ` [pbs-devel] applied: [PATCH proxmox-backup 0/3] follow ups for gc job status series Fabian Grünbichler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240422113834.842169-5-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox