container labels and room event type.

This commit is contained in:
Miroslav Šedivý
2023-12-01 00:13:48 +01:00
parent 7d70f7ac9b
commit b62ac1097c
3 changed files with 29 additions and 12 deletions
+2
View File
@@ -34,6 +34,8 @@ func (manager *RoomManagerCtx) containerToEntry(container dockerTypes.Container)
Status: container.Status,
Created: time.Unix(container.Created, 0),
Labels: labels.UserDefined,
ContainerLabels: container.Labels,
}
if labels.Mux {
+11 -9
View File
@@ -93,8 +93,9 @@ func (e *events) Start() {
e.broadcast(types.RoomEvent{
ID: room.id,
Action: "ready",
Labels: room.labels,
Action: types.RoomEventReady,
ContainerLabels: room.labels,
})
case msg := <-msgs:
roomId := msg.Actor.ID[:12]
@@ -105,30 +106,31 @@ func (e *events) Start() {
Str("action", msg.Action).
Msg("got docker event")
action := ""
var action types.RoomEventAction
switch msg.Action {
case "create":
action = "created"
action = types.RoomEventCreated
case "start":
action = "started"
action = types.RoomEventStarted
e.waitForRoomReady(roomId, labels)
case "health_status: healthy":
action = "ready"
action = types.RoomEventReady
// ignore if room was already ready
if !e.setRoomReady(roomId) {
continue
}
case "stop":
action = "stopped"
action = types.RoomEventStopped
e.setRoomNotReady(roomId)
case "destroy":
action = "destroyed"
action = types.RoomEventDestroyed
}
e.broadcast(types.RoomEvent{
ID: roomId,
Action: action,
Labels: labels,
ContainerLabels: labels,
})
}
}
+15 -2
View File
@@ -27,6 +27,8 @@ type RoomEntry struct {
Status string `json:"status"`
Created time.Time `json:"created"`
Labels map[string]string `json:"labels,omitempty"`
ContainerLabels map[string]string `json:"-"` // for internal use
}
type MountType string
@@ -139,10 +141,21 @@ type RoomMember struct {
Muted bool `json:"muted"`
}
type RoomEventAction string
const (
RoomEventCreated RoomEventAction = "created"
RoomEventStarted RoomEventAction = "started"
RoomEventReady RoomEventAction = "ready"
RoomEventStopped RoomEventAction = "stopped"
RoomEventDestroyed RoomEventAction = "destroyed"
)
type RoomEvent struct {
ID string `json:"id"`
Action string `json:"action"`
Labels map[string]string `json:"-"`
Action RoomEventAction `json:"action"`
ContainerLabels map[string]string `json:"-"` // for internal use
}
var ErrRoomNotFound = fmt.Errorf("room not found")