public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2 7/9] api2/status: use the TaskListInfoIterator here
Date: Mon, 28 Sep 2020 15:32:10 +0200	[thread overview]
Message-ID: <20200928133212.409-8-d.csapak@proxmox.com> (raw)
In-Reply-To: <20200928133212.409-1-d.csapak@proxmox.com>

this means that limiting with epoch now works correctly
also change the api type to i64, since that is what the starttime is
saved as

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v1:
* adapt to new TaskListInfoIterator::new signature
 src/api2/status.rs | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/src/api2/status.rs b/src/api2/status.rs
index eb8c43cd..fd40f14d 100644
--- a/src/api2/status.rs
+++ b/src/api2/status.rs
@@ -182,7 +182,7 @@ fn datastore_status(
     input: {
         properties: {
             since: {
-                type: u64,
+                type: i64,
                 description: "Only list tasks since this UNIX epoch.",
                 optional: true,
             },
@@ -200,6 +200,7 @@ fn datastore_status(
 )]
 /// List tasks.
 pub fn list_tasks(
+    since: Option<i64>,
     _param: Value,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Vec<TaskListItem>, Error> {
@@ -209,13 +210,28 @@ pub fn list_tasks(
     let user_privs = user_info.lookup_privs(&userid, &["system", "tasks"]);
 
     let list_all = (user_privs & PRIV_SYS_AUDIT) != 0;
-
-    // TODO: replace with call that gets all task since 'since' epoch
-    let list: Vec<TaskListItem> = server::read_task_list()?
-        .into_iter()
-        .map(TaskListItem::from)
-        .filter(|entry| list_all || entry.user == userid)
-        .collect();
+    let since = since.unwrap_or_else(|| 0);
+
+    let list: Vec<TaskListItem> = server::TaskListInfoIterator::new(false)?
+        .take_while(|info| {
+            match info {
+                Ok(info) => info.upid.starttime > since,
+                Err(_) => false
+            }
+        })
+        .filter_map(|info| {
+            match info {
+                Ok(info) => {
+                    if list_all || info.upid.userid == userid {
+                        Some(Ok(TaskListItem::from(info)))
+                    } else {
+                        None
+                    }
+                }
+                Err(err) => Some(Err(err))
+            }
+        })
+        .collect::<Result<Vec<TaskListItem>, Error>>()?;
 
     Ok(list.into())
 }
-- 
2.20.1





  parent reply	other threads:[~2020-09-28 13:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-28 13:32 [pbs-devel] [PATCH proxmox-backup v2 0/9] improve task list handling Dominik Csapak
2020-09-28 13:32 ` [pbs-devel] [PATCH proxmox-backup v2 1/9] tools: add logrotate module Dominik Csapak
2020-09-28 13:32 ` [pbs-devel] [PATCH proxmox-backup v2 2/9] server/worker_task: refactor locking of the task list Dominik Csapak
2020-09-28 13:32 ` [pbs-devel] [PATCH proxmox-backup v2 3/9] server/worker_task: split task list file into two Dominik Csapak
2020-09-28 13:32 ` [pbs-devel] [PATCH proxmox-backup v2 4/9] server/worker_task: write older tasks into archive file Dominik Csapak
2020-09-28 13:32 ` [pbs-devel] [PATCH proxmox-backup v2 5/9] server/worker_task: add TaskListInfoIterator Dominik Csapak
2020-09-28 13:32 ` [pbs-devel] [PATCH proxmox-backup v2 6/9] api2/node/tasks: use TaskListInfoIterator instead of read_task_list Dominik Csapak
2020-09-28 13:32 ` Dominik Csapak [this message]
2020-09-28 13:32 ` [pbs-devel] [PATCH proxmox-backup v2 8/9] server/worker_task: remove unecessary read_task_list Dominik Csapak
2020-09-28 13:32 ` [pbs-devel] [PATCH proxmox-backup v2 9/9] proxmox-backup-proxy: add task archive rotation Dominik Csapak
2020-09-29  7:16 ` [pbs-devel] applied: [PATCH proxmox-backup v2 0/9] improve task list handling Dietmar Maurer

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=20200928133212.409-8-d.csapak@proxmox.com \
    --to=d.csapak@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal