From b62ac1097cbd535d8ce06d8c954ad1f3c233bf6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Fri, 1 Dec 2023 00:13:48 +0100 Subject: [PATCH] container labels and room event type. --- internal/room/containers.go | 2 ++ internal/room/events.go | 20 +++++++++++--------- internal/types/room.go | 19 ++++++++++++++++--- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/internal/room/containers.go b/internal/room/containers.go index 05bfcd1..e24588c 100644 --- a/internal/room/containers.go +++ b/internal/room/containers.go @@ -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 { diff --git a/internal/room/events.go b/internal/room/events.go index 9908c57..17a8f31 100644 --- a/internal/room/events.go +++ b/internal/room/events.go @@ -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, }) } } diff --git a/internal/types/room.go b/internal/types/room.go index 89032eb..1efd8b8 100644 --- a/internal/types/room.go +++ b/internal/types/room.go @@ -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:"-"` + ID string `json:"id"` + Action RoomEventAction `json:"action"` + + ContainerLabels map[string]string `json:"-"` // for internal use } var ErrRoomNotFound = fmt.Errorf("room not found")