feat(protocol): job messages, protocol version and job model (#7)

This commit is contained in:
2026-10-12 18:38:39 +02:00
parent eb41967cd1
commit 9e09de0a16
8 changed files with 314 additions and 16 deletions
+9 -1
View File
@@ -2,7 +2,10 @@
// open browser streams.
package events
import "sync"
import (
"strconv"
"sync"
)
// Topic names what changed. Subscribers refetch that part of the UI.
type Topic string
@@ -11,8 +14,13 @@ type Topic string
const (
Services Topic = "services"
Agents Topic = "agents"
Jobs Topic = "jobs" // a job was created or changed status
)
// JobTopic is signalled when job id gets new output or changes status. The
// name avoids ":" so it is safe inside hx-trigger="sse:job-42".
func JobTopic(id int64) Topic { return Topic("job-" + strconv.FormatInt(id, 10)) }
// Broker is an in-process publish/subscribe hub.
type Broker struct {
mu sync.Mutex
+4
View File
@@ -46,3 +46,7 @@ func TestBroker_SlowSubscriberDoesNotBlockPublish(t *testing.T) {
t.Fatal("Publish blocked on a slow subscriber")
}
}
func TestJobTopic(t *testing.T) {
assert.Equal(t, Topic("job-42"), JobTopic(42))
}