Skip to content

Commit 3d4c66c

Browse files
status: enable setting custom sub-server statuses
1 parent 3b83d6e commit 3d4c66c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

status/manager.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ type SubServerStatus struct {
2323
// been started.
2424
Running bool
2525

26+
// customStatus is a string that details a custom status of the
27+
// sub-server, if the the sub-server is in a custom state. This status
28+
// can be set to a unique status that only exists for the specific
29+
// sub-server, and will be displayed to the user with the
30+
// litrpc.SubServerStatus.
31+
customStatus string
32+
2633
// Err will be a non-empty string if the sub-server failed to start.
2734
Err string
2835
}
@@ -105,6 +112,20 @@ func (s *Manager) registerSubServerUnsafe(name string, disabled bool,
105112
s.subServers[name] = ss
106113
}
107114

115+
// SetCustomStatus updates the custom status of the given sub-server to the
116+
// passed status.
117+
func (s *Manager) SetCustomStatus(name, customStatus string) {
118+
s.mu.Lock()
119+
defer s.mu.Unlock()
120+
121+
ss, ok := s.subServers[name]
122+
if !ok {
123+
return
124+
}
125+
126+
ss.customStatus = customStatus
127+
}
128+
108129
// GetStatus returns the current status of a given sub-server. This will
109130
// silently fail if the referenced sub-server has not yet been registered.
110131
func (s *Manager) GetStatus(name string) (*SubServerStatus, error) {
@@ -155,6 +176,7 @@ func (s *Manager) SetRunning(name string) {
155176
}
156177

157178
ss.Running = true
179+
ss.customStatus = ""
158180
}
159181

160182
// SetStopped can be used to set the status of a sub-server as not Running and
@@ -175,6 +197,7 @@ func (s *Manager) SetStopped(name string) {
175197

176198
ss.Running = false
177199
ss.Err = ""
200+
ss.customStatus = ""
178201
}
179202

180203
// SetErrored can be used to set the status of a sub-server as not Running
@@ -201,4 +224,5 @@ func (s *Manager) SetErrored(name string, errStr string,
201224

202225
ss.Running = false
203226
ss.Err = err
227+
ss.customStatus = ""
204228
}

0 commit comments

Comments
 (0)