Skip to content

Commit e35a6ab

Browse files
committed
fix: change SupervisorStatusType to enum
1 parent b887bff commit e35a6ab

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

src/api.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ func (a *App) getSupervisorStatusByID(w http.ResponseWriter, r *http.Request) {
225225
}
226226

227227
func (a *App) getAllSupervisors(w http.ResponseWriter, r *http.Request) {
228-
// check if we want only active supervisors
229228
activeOnly := r.URL.Query().Get("active") == "true"
230229

231230
var supervisors []SupervisorStatus

src/status.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ func addDummySupervisors(statusRegistry *StatusRegistry, log *slog.Logger) {
3030
{
3131
ConsumerID: "worker_amd_001",
3232
GPUType: "AMD",
33-
Status: "active",
33+
Status: SupervisorStateActive,
3434
LastSeen: now, // now
3535
StartedAt: now.Add(-2 * time.Hour), // 2hours ago
3636
},
3737
{
3838
ConsumerID: "worker_nvidia_002",
3939
GPUType: "NVIDIA",
40-
Status: "active",
40+
Status: SupervisorStateActive,
4141
LastSeen: now.Add(-30 * time.Second), // 30 seconds ago
4242
StartedAt: now.Add(-1 * time.Hour), // 1 hour ago
4343
},
4444
{
4545
ConsumerID: "worker_tt_003",
4646
GPUType: "TT",
47-
Status: "inactive",
47+
Status: SupervisorStateInactive,
4848
LastSeen: now.Add(-5 * time.Minute), // seen 5 minutes ago
4949
StartedAt: now.Add(-3 * time.Hour), // 3 hours ago
5050
},
@@ -103,7 +103,7 @@ func (sr *StatusRegistry) GetActiveSupervisors() ([]SupervisorStatus, error) {
103103

104104
var activeSupervisors []SupervisorStatus
105105
for _, supervisor := range allSupervisors {
106-
if supervisor.Status == "active" {
106+
if supervisor.Status == SupervisorStateActive {
107107
activeSupervisors = append(activeSupervisors, supervisor)
108108
}
109109
}

src/util.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
)
88

99
const (
10-
StreamName = "jobs:stream"
11-
ConsumerGroup = "workers"
12-
MaxRetries = 3
13-
RetryDelay = 5 * time.Second
10+
StreamName = "jobs:stream"
11+
ConsumerGroup = "workers"
12+
SupervisorStatusKey = "supervisors:status"
13+
MaxRetries = 3
14+
RetryDelay = 5 * time.Second
1415
)
1516

1617
type Job struct {
@@ -22,12 +23,20 @@ type Job struct {
2223
RequiredGPU string `json:"gpu"`
2324
}
2425

26+
type SupervisorState string
27+
28+
const (
29+
SupervisorStateActive SupervisorState = "active"
30+
SupervisorStateInactive SupervisorState = "inactive"
31+
SupervisorStateFailed SupervisorState = "failed"
32+
)
33+
2534
type SupervisorStatus struct {
26-
ConsumerID string `json:"consumer_id"`
27-
GPUType string `json:"gpu_type"`
28-
Status string `json:"status"` // "active", "inactive", "failed"
29-
LastSeen time.Time `json:"last_seen"`
30-
StartedAt time.Time `json:"started_at"`
35+
ConsumerID string `json:"consumer_id"`
36+
GPUType string `json:"gpu_type"`
37+
Status SupervisorState `json:"status"`
38+
LastSeen time.Time `json:"last_seen"`
39+
StartedAt time.Time `json:"started_at"`
3140
}
3241

3342
func generateJobID() string {

0 commit comments

Comments
 (0)