Преглед изворни кода

bin/tau: get tasks by looping through ids

ghassmo пре 4 година
родитељ
комит
a831a5855d
3 измењених фајлова са 24 додато и 13 уклоњено
  1. 4 4
      bin/tau/tau-cli/src/jsonrpc.rs
  2. 12 2
      bin/tau/tau-cli/src/main.rs
  3. 8 7
      bin/tau/taud/src/jsonrpc.rs

+ 4 - 4
bin/tau/tau-cli/src/jsonrpc.rs

@@ -52,10 +52,10 @@ pub async fn add(url: &str, params: Value) -> Result<Value> {
 }
 }
 
 
 // List tasks
 // List tasks
-// --> {"jsonrpc": "2.0", "method": "list", "params": [], "id": 1}
-// <-- {"jsonrpc": "2.0", "result": [task, ...], "id": 1}
-pub async fn list(url: &str, params: Value) -> Result<Value> {
-    let req = jsonrpc::request(json!("list"), json!(params));
+// --> {"jsonrpc": "2.0", "method": "get_ids", "params": [], "id": 1}
+// <-- {"jsonrpc": "2.0", "result": [task_id, ...], "id": 1}
+pub async fn get_ids(url: &str, params: Value) -> Result<Value> {
+    let req = jsonrpc::request(json!("get_ids"), json!(params));
     request(req, url.to_string()).await
     request(req, url.to_string()).await
 }
 }
 
 

+ 12 - 2
bin/tau/tau-cli/src/main.rs

@@ -89,8 +89,18 @@ async fn start(mut options: cli::CliTau) -> Result<()> {
         },
         },
 
 
         Some(CliTauSubCommands::List {}) | None => {
         Some(CliTauSubCommands::List {}) | None => {
-            let tasks = jsonrpc::list(rpc_addr, json!([])).await?;
-            let mut tasks: Vec<TaskInfo> = serde_json::from_value(tasks)?;
+            let task_ids = jsonrpc::get_ids(rpc_addr, json!([])).await?;
+            let mut tasks: Vec<TaskInfo> = vec![];
+            if let Some(ids) = task_ids.as_array() {
+                for id in ids {
+                    let id = if id.is_u64() { id.as_u64().unwrap() } else { continue };
+                    let task = jsonrpc::get_task_by_id(&rpc_addr, id).await?;
+                    let taskinfo: TaskInfo = serde_json::from_value(task.clone())?;
+                    tasks.push(taskinfo);
+                }
+            }
+
+            // let mut tasks: Vec<TaskInfo> = serde_json::from_value(tasks)?;
             print_list_of_task(&mut tasks, options.filters)?;
             print_list_of_task(&mut tasks, options.filters)?;
         }
         }
     }
     }

+ 8 - 7
bin/tau/taud/src/jsonrpc.rs

@@ -52,7 +52,7 @@ impl RequestHandler for JsonRpcInterface {
 
 
         let rep = match req.method.as_str() {
         let rep = match req.method.as_str() {
             Some("add") => self.add(req.params).await,
             Some("add") => self.add(req.params).await,
-            Some("list") => self.list(req.params).await,
+            Some("get_ids") => self.get_ids(req.params).await,
             Some("update") => self.update(req.params).await,
             Some("update") => self.update(req.params).await,
             Some("set_state") => self.set_state(req.params).await,
             Some("set_state") => self.set_state(req.params).await,
             Some("set_comment") => self.set_comment(req.params).await,
             Some("set_comment") => self.set_comment(req.params).await,
@@ -113,12 +113,13 @@ impl JsonRpcInterface {
 
 
     // RPCAPI:
     // RPCAPI:
     // List tasks
     // List tasks
-    // --> {"jsonrpc": "2.0", "method": "list", "params": [], "id": 1}
-    // <-- {"jsonrpc": "2.0", "result": [task, ...], "id": 1}
-    async fn list(&self, params: Value) -> TaudResult<Value> {
-        debug!(target: "tau", "JsonRpc::list() params {}", params);
-        let tks = MonthTasks::load_current_open_tasks(&self.dataset_path)?;
-        Ok(json!(tks))
+    // --> {"jsonrpc": "2.0", "method": "get_ids", "params": [], "id": 1}
+    // <-- {"jsonrpc": "2.0", "result": [task_id, ...], "id": 1}
+    async fn get_ids(&self, params: Value) -> TaudResult<Value> {
+        debug!(target: "tau", "JsonRpc::get_ids() params {}", params);
+        let tasks = MonthTasks::load_current_open_tasks(&self.dataset_path)?;
+        let task_ids: Vec<u32> = tasks.iter().map(|task| task.get_id()).collect();
+        Ok(json!(task_ids))
     }
     }
 
 
     // RPCAPI:
     // RPCAPI: