list returns info about all tracked processes. Exited processes older than exitedProcessReapAge are removed. If chatID is non-empty, only processes belonging to that chat are returned.
(chatID string)
| 241 | // If chatID is non-empty, only processes belonging to that |
| 242 | // chat are returned. |
| 243 | func (m *manager) list(chatID string) []workspacesdk.ProcessInfo { |
| 244 | m.mu.Lock() |
| 245 | defer m.mu.Unlock() |
| 246 | |
| 247 | now := m.clock.Now() |
| 248 | infos := make([]workspacesdk.ProcessInfo, 0, len(m.procs)) |
| 249 | for id, proc := range m.procs { |
| 250 | info := proc.info() |
| 251 | // Reap processes that exited more than 5 minutes ago |
| 252 | // to prevent unbounded map growth. |
| 253 | if !info.Running && info.ExitedAt != nil { |
| 254 | exitedAt := time.Unix(*info.ExitedAt, 0) |
| 255 | if now.Sub(exitedAt) > exitedProcessReapAge { |
| 256 | delete(m.procs, id) |
| 257 | continue |
| 258 | } |
| 259 | } |
| 260 | // Filter by chatID if provided. |
| 261 | if chatID != "" && proc.chatID != chatID { |
| 262 | continue |
| 263 | } |
| 264 | infos = append(infos, info) |
| 265 | } |
| 266 | return infos |
| 267 | } |
| 268 | |
| 269 | // signal sends a signal to a running process. It returns |
| 270 | // sentinel errors errProcessNotFound and errProcessNotRunning |
no test coverage detected