1+ use serde_json:: json;
12use std:: fmt;
23use std:: rc:: Rc ;
34use std:: time:: Duration ;
@@ -45,6 +46,37 @@ impl fmt::Debug for TaskRuntimeState {
4546 }
4647}
4748
49+ impl TaskRuntimeState {
50+ fn dump ( & self ) -> serde_json:: Value {
51+ match self {
52+ Self :: Waiting ( info) => json ! ( {
53+ "state" : "Waiting" ,
54+ "unfinished_deps" : info. unfinished_deps,
55+ } ) ,
56+ Self :: Assigned ( w_id) => json ! ( {
57+ "state" : "Assigned" ,
58+ "worker_id" : w_id,
59+ } ) ,
60+ Self :: Stealing ( from_w, to_w) => json ! ( {
61+ "state" : "Stealing" ,
62+ "from_worker" : from_w,
63+ "to_worker" : to_w,
64+ } ) ,
65+ Self :: Running { worker_id, .. } => json ! ( {
66+ "state" : "Running" ,
67+ "worker_id" : worker_id,
68+ } ) ,
69+ Self :: RunningMultiNode ( ws) => json ! ( {
70+ "state" : "RunningMultiNode" ,
71+ "worker_ids" : ws,
72+ } ) ,
73+ Self :: Finished => json ! ( {
74+ "state" : "Finished" ,
75+ } ) ,
76+ }
77+ }
78+ }
79+
4880bitflags:: bitflags! {
4981 #[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
5082 pub struct TaskFlags : u32 {
@@ -66,6 +98,18 @@ pub struct TaskConfiguration {
6698 pub body : Box < [ u8 ] > ,
6799}
68100
101+ impl TaskConfiguration {
102+ pub fn dump ( & self ) -> serde_json:: Value {
103+ json ! ( {
104+ "resources" : self . resources,
105+ "user_priority" : self . user_priority,
106+ "time_limit" : self . time_limit,
107+ "crash_limit" : self . crash_limit,
108+ "body_len" : self . body. len( ) ,
109+ } )
110+ }
111+ }
112+
69113#[ cfg_attr( test, derive( Eq , PartialEq ) ) ]
70114pub struct Task {
71115 pub id : TaskId ,
@@ -92,6 +136,20 @@ impl fmt::Debug for Task {
92136}
93137
94138impl Task {
139+ pub fn dump ( & self ) -> serde_json:: Value {
140+ json ! ( {
141+ "id" : self . id. to_string( ) ,
142+ "state" : self . state. dump( ) ,
143+ "consumers" : self . consumers,
144+ "task_deps" : self . task_deps,
145+ "flags" : self . flags. bits( ) ,
146+ "scheduler_priority" : self . scheduler_priority,
147+ "instance_id" : self . instance_id,
148+ "crash_counter" : self . crash_counter,
149+ "configuration" : self . configuration. dump( ) ,
150+ } )
151+ }
152+
95153 pub fn new (
96154 id : TaskId ,
97155 task_deps : ThinVec < TaskId > ,
0 commit comments