Browse Source

bin/tau: add more debug messgaes

ghassmo 4 years ago
parent
commit
3986a98561

+ 10 - 3
bin/tau/taud/src/jsonrpc.rs

@@ -90,6 +90,7 @@ impl JsonRpcInterface {
     //      }
     // <-- {"jsonrpc": "2.0", "result": true, "id": 1}
     async fn add(&self, params: Value) -> TaudResult<Value> {
+        debug!(target: "tau", "JsonRpc::add() params {}", params);
         let args = params.as_array().unwrap();
 
         let task: BaseTaskInfo = serde_json::from_value(args[0].clone())?;
@@ -107,7 +108,8 @@ impl JsonRpcInterface {
     // 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> {
+    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))
     }
@@ -117,13 +119,14 @@ impl JsonRpcInterface {
     // --> {"jsonrpc": "2.0", "method": "update", "params": [task_id, {"title": "new title"} ], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": true, "id": 1}
     async fn update(&self, params: Value) -> TaudResult<Value> {
+        debug!(target: "tau", "JsonRpc::update() params {}", params);
         let args = params.as_array().unwrap();
 
         if args.len() != 2 {
             return Err(TaudError::InvalidData("len of params should be 2".into()))
         }
 
-        let task = self.check_data_for_update(&args[0], &args[1])?;
+        let task = self.check_params_for_update(&args[0], &args[1])?;
 
         self.notify_queue_sender.send(Some(task)).await.map_err(Error::from)?;
 
@@ -135,6 +138,7 @@ impl JsonRpcInterface {
     // --> {"jsonrpc": "2.0", "method": "get_state", "params": [task_id], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": "state", "id": 1}
     async fn get_state(&self, params: Value) -> TaudResult<Value> {
+        debug!(target: "tau", "JsonRpc::get_state() params {}", params);
         let args = params.as_array().unwrap();
 
         if args.len() != 1 {
@@ -151,6 +155,7 @@ impl JsonRpcInterface {
     // --> {"jsonrpc": "2.0", "method": "set_state", "params": [task_id, state], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": true, "id": 1}
     async fn set_state(&self, params: Value) -> TaudResult<Value> {
+        debug!(target: "tau", "JsonRpc::set_state() params {}", params);
         let args = params.as_array().unwrap();
 
         if args.len() != 2 {
@@ -172,6 +177,7 @@ impl JsonRpcInterface {
     // --> {"jsonrpc": "2.0", "method": "set_comment", "params": [task_id, comment_author, comment_content], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": true, "id": 1}
     async fn set_comment(&self, params: Value) -> TaudResult<Value> {
+        debug!(target: "tau", "JsonRpc::set_comment() params {}", params);
         let args = params.as_array().unwrap();
 
         if args.len() != 3 {
@@ -193,6 +199,7 @@ impl JsonRpcInterface {
     // --> {"jsonrpc": "2.0", "method": "get_by_id", "params": [task_id], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": "task", "id": 1}
     async fn get_by_id(&self, params: Value) -> TaudResult<Value> {
+        debug!(target: "tau", "JsonRpc::get_by_id() params {}", params);
         let args = params.as_array().unwrap();
 
         if args.len() != 1 {
@@ -213,7 +220,7 @@ impl JsonRpcInterface {
         task.ok_or(TaudError::InvalidId)
     }
 
-    fn check_data_for_update(&self, task_id: &Value, data: &Value) -> TaudResult<TaskInfo> {
+    fn check_params_for_update(&self, task_id: &Value, data: &Value) -> TaudResult<TaskInfo> {
         let mut task: TaskInfo = self.load_task_by_id(task_id)?;
 
         if !data.is_object() {

+ 1 - 1
bin/tau/taud/src/main.rs

@@ -80,7 +80,7 @@ async fn start(settings: Settings, executor: Arc<Executor<'_>>) -> TaudResult<()
     let recv_update_from_raft: smol::Task<TaudResult<()>> = executor.spawn(async move {
         loop {
             let task = commits.recv().await.map_err(Error::from)?;
-            info!(target: "tau", "update from the commits");
+            info!(target: "tau", "receive update from the commits {:?}", task);
             task.save(&dataset_path_cloned)?;
         }
     });

+ 13 - 4
bin/tau/taud/src/month_tasks.rs

@@ -1,12 +1,13 @@
 use std::path::{Path, PathBuf};
 
 use chrono::{TimeZone, Utc};
+use log::debug;
 use serde::{Deserialize, Serialize};
 
 use crate::{
     error::{TaudError, TaudResult},
-    task_info::TaskInfo,
-    util::{get_current_time, Timestamp},
+    task_debug::TaskInfo,
+    util::{get_current_time, load, save, Timestamp},
 };
 
 #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
@@ -21,12 +22,14 @@ impl MonthTasks {
     }
 
     pub fn add(&mut self, ref_id: &str) {
+        debug!(target: "tau", "MonthTasks::add()");
         if !self.task_tks.contains(&ref_id.into()) {
             self.task_tks.push(ref_id.into());
         }
     }
 
     pub fn objects(&self, dataset_path: &Path) -> TaudResult<Vec<TaskInfo>> {
+        debug!(target: "tau", "MonthTasks::objects()");
         let mut tks: Vec<TaskInfo> = vec![];
 
         for ref_id in self.task_tks.iter() {
@@ -37,26 +40,31 @@ impl MonthTasks {
     }
 
     pub fn remove(&mut self, ref_id: &str) {
+        debug!(target: "tau", "MonthTasks::remove()");
         if let Some(index) = self.task_tks.iter().position(|t| *t == ref_id) {
             self.task_tks.remove(index);
         }
     }
 
     pub fn set_date(&mut self, date: &Timestamp) {
+        debug!(target: "tau", "MonthTasks::set_date()");
         self.created_at = date.clone();
     }
 
     fn get_path(date: &Timestamp, dataset_path: &Path) -> PathBuf {
+        debug!(target: "tau", "MonthTasks::get_path()");
         dataset_path.join("month").join(Utc.timestamp(date.0, 0).format("%m%y").to_string())
     }
 
     pub fn save(&self, dataset_path: &Path) -> TaudResult<()> {
-        crate::util::save::<Self>(&Self::get_path(&self.created_at, dataset_path), self)
+        debug!(target: "tau", "MonthTasks::save()");
+        save::<Self>(&Self::get_path(&self.created_at, dataset_path), self)
             .map_err(TaudError::Darkfi)
     }
 
     pub fn load_or_create(date: &Timestamp, dataset_path: &Path) -> TaudResult<Self> {
-        match crate::util::load::<Self>(&Self::get_path(date, dataset_path)) {
+        debug!(target: "tau", "MonthTasks::load_or_create()");
+        match load::<Self>(&Self::get_path(date, dataset_path)) {
             Ok(mt) => Ok(mt),
             Err(_) => {
                 let mut mt = Self::new(&[]);
@@ -68,6 +76,7 @@ impl MonthTasks {
     }
 
     pub fn load_current_open_tasks(dataset_path: &Path) -> TaudResult<Vec<TaskInfo>> {
+        debug!(target: "tau", "MonthTasks::load_current_open_tasks()");
         let mt = Self::load_or_create(&get_current_time(), dataset_path)?;
         Ok(mt.objects(dataset_path)?.into_iter().filter(|t| t.get_state() != "stop").collect())
     }

+ 20 - 7
bin/tau/taud/src/task_info.rs

@@ -3,17 +3,15 @@ use std::{
     path::{Path, PathBuf},
 };
 
+use log::debug;
 use serde::{Deserialize, Serialize};
 
-use darkfi::util::serial::{Decodable, Encodable, SerialDecodable, SerialEncodable};
-
-use darkfi::util::serial::VarInt;
-
 use crate::{
     error::{TaudError, TaudResult},
     month_tasks::MonthTasks,
-    util::{find_free_id, get_current_time, random_ref_id, Timestamp},
+    util::{find_free_id, get_current_time, load, random_ref_id, save, Timestamp},
 };
+use darkfi::util::serial::{Decodable, Encodable, SerialDecodable, SerialEncodable, VarInt};
 
 #[derive(Clone, Debug, Serialize, Deserialize, SerialEncodable, SerialDecodable, PartialEq)]
 struct TaskEvent {
@@ -104,12 +102,14 @@ impl TaskInfo {
     }
 
     pub fn load(ref_id: &str, dataset_path: &Path) -> TaudResult<Self> {
-        let task = crate::util::load::<Self>(&Self::get_path(ref_id, dataset_path))?;
+        debug!(target: "tau", "TaskInfo::load()");
+        let task = load::<Self>(&Self::get_path(ref_id, dataset_path))?;
         Ok(task)
     }
 
     pub fn save(&self, dataset_path: &Path) -> TaudResult<()> {
-        crate::util::save::<Self>(&Self::get_path(&self.ref_id, dataset_path), self)
+        debug!(target: "tau", "TaskInfo::save()");
+        save::<Self>(&Self::get_path(&self.ref_id, dataset_path), self)
             .map_err(TaudError::Darkfi)?;
 
         if self.get_state() == "stop" {
@@ -122,18 +122,21 @@ impl TaskInfo {
     }
 
     pub fn activate(&self, path: &Path) -> TaudResult<()> {
+        debug!(target: "tau", "TaskInfo::activate()");
         let mut mt = MonthTasks::load_or_create(&self.created_at, path)?;
         mt.add(&self.ref_id);
         mt.save(path)
     }
 
     pub fn deactivate(&self, path: &Path) -> TaudResult<()> {
+        debug!(target: "tau", "TaskInfo::deactivate()");
         let mut mt = MonthTasks::load_or_create(&self.created_at, path)?;
         mt.remove(&self.ref_id);
         mt.save(path)
     }
 
     pub fn get_state(&self) -> String {
+        debug!(target: "tau", "TaskInfo::get_state()");
         if let Some(ev) = self.events.0.last() {
             ev.action.clone()
         } else {
@@ -142,42 +145,52 @@ impl TaskInfo {
     }
 
     fn get_path(ref_id: &str, dataset_path: &Path) -> PathBuf {
+        debug!(target: "tau", "TaskInfo::get_path()");
         dataset_path.join("task").join(ref_id)
     }
 
     pub fn get_id(&self) -> u32 {
+        debug!(target: "tau", "TaskInfo::get_id()");
         self.id
     }
 
     pub fn set_title(&mut self, title: &str) {
+        debug!(target: "tau", "TaskInfo::set_title()");
         self.title = title.into();
     }
 
     pub fn set_desc(&mut self, desc: &str) {
+        debug!(target: "tau", "TaskInfo::set_desc()");
         self.desc = desc.into();
     }
 
     pub fn set_assign(&mut self, assign: &[String]) {
+        debug!(target: "tau", "TaskInfo::set_assign()");
         self.assign = TaskAssigns(assign.to_owned());
     }
 
     pub fn set_project(&mut self, project: &[String]) {
+        debug!(target: "tau", "TaskInfo::set_project()");
         self.project = TaskProjects(project.to_owned());
     }
 
     pub fn set_comment(&mut self, c: Comment) {
+        debug!(target: "tau", "TaskInfo::set_comment()");
         self.comments.0.push(c);
     }
 
     pub fn set_rank(&mut self, r: f32) {
+        debug!(target: "tau", "TaskInfo::set_rank()");
         self.rank = r;
     }
 
     pub fn set_due(&mut self, d: Option<Timestamp>) {
+        debug!(target: "tau", "TaskInfo::set_due()");
         self.due = d;
     }
 
     pub fn set_state(&mut self, action: &str) {
+        debug!(target: "tau", "TaskInfo::set_state()");
         if self.get_state() == action {
             return
         }