Implement platform management features
This commit is contained in:
@@ -8,14 +8,28 @@ import (
|
||||
|
||||
const logEventSubscriberBuffer = 512
|
||||
|
||||
type LogEventSubscriptionEventKind string
|
||||
|
||||
const (
|
||||
LogEventSubscriptionEventLog LogEventSubscriptionEventKind = "log"
|
||||
LogEventSubscriptionEventProcessState LogEventSubscriptionEventKind = "process-state"
|
||||
)
|
||||
|
||||
type LogEventSubscriptionEvent struct {
|
||||
Kind LogEventSubscriptionEventKind
|
||||
LogEvent domain.LogStreamEvent
|
||||
ServerInstanceID string
|
||||
ProcessState domain.ServerInstanceState
|
||||
}
|
||||
|
||||
type LogEventSubscription struct {
|
||||
Events <-chan domain.LogStreamEvent
|
||||
Events <-chan LogEventSubscriptionEvent
|
||||
Close func()
|
||||
}
|
||||
|
||||
type logEventSubscriber struct {
|
||||
serverInstanceID string
|
||||
events chan domain.LogStreamEvent
|
||||
events chan LogEventSubscriptionEvent
|
||||
}
|
||||
|
||||
func (svc *CoreService) SubscribeLogEvents(serverInstanceID string) (LogEventSubscription, error) {
|
||||
@@ -26,7 +40,7 @@ func (svc *CoreService) SubscribeLogEvents(serverInstanceID string) (LogEventSub
|
||||
if _, err := svc.store.ServerInstances().Get(serverInstanceID); err != nil {
|
||||
return LogEventSubscription{}, err
|
||||
}
|
||||
events := make(chan domain.LogStreamEvent, logEventSubscriberBuffer)
|
||||
events := make(chan LogEventSubscriptionEvent, logEventSubscriberBuffer)
|
||||
svc.logEventMu.Lock()
|
||||
svc.logEventSubscriberSeq++
|
||||
id := svc.logEventSubscriberSeq
|
||||
@@ -55,18 +69,36 @@ func (svc *CoreService) publishLogEvents(stream domain.LogStream, entries []doma
|
||||
if len(entries) == 0 {
|
||||
return
|
||||
}
|
||||
events := make([]domain.LogStreamEvent, len(entries))
|
||||
events := make([]LogEventSubscriptionEvent, len(entries))
|
||||
for index, entry := range entries {
|
||||
events[index] = domain.CopyLogStreamEvent(domain.LogStreamEvent{
|
||||
ServerInstanceID: stream.ServerInstanceID,
|
||||
Stream: stream,
|
||||
Entry: entry,
|
||||
LatestSeq: stream.LatestSeq,
|
||||
})
|
||||
events[index] = LogEventSubscriptionEvent{
|
||||
Kind: LogEventSubscriptionEventLog,
|
||||
LogEvent: domain.CopyLogStreamEvent(domain.LogStreamEvent{
|
||||
ServerInstanceID: stream.ServerInstanceID,
|
||||
Stream: stream,
|
||||
Entry: entry,
|
||||
LatestSeq: stream.LatestSeq,
|
||||
}),
|
||||
}
|
||||
}
|
||||
svc.publishLogSubscriptionEvents(stream.ServerInstanceID, events)
|
||||
}
|
||||
|
||||
func (svc *CoreService) publishLogProcessState(instance domain.ServerInstance) {
|
||||
svc.publishLogSubscriptionEvents(instance.ID, []LogEventSubscriptionEvent{{
|
||||
Kind: LogEventSubscriptionEventProcessState,
|
||||
ServerInstanceID: instance.ID,
|
||||
ProcessState: instance.State,
|
||||
}})
|
||||
}
|
||||
|
||||
func (svc *CoreService) publishLogSubscriptionEvents(serverInstanceID string, events []LogEventSubscriptionEvent) {
|
||||
if len(events) == 0 {
|
||||
return
|
||||
}
|
||||
svc.logEventMu.Lock()
|
||||
for id, subscriber := range svc.logEventSubscribers {
|
||||
if subscriber.serverInstanceID != stream.ServerInstanceID {
|
||||
if subscriber.serverInstanceID != serverInstanceID {
|
||||
continue
|
||||
}
|
||||
dropped := false
|
||||
|
||||
Reference in New Issue
Block a user