Reconnect the app's command channel after sleep; list clients from it
This commit is contained in:
@@ -45,11 +45,11 @@ func New(dataDir string, portFirst int) (*Server, error) {
|
||||
|
||||
s := &Server{
|
||||
hub: newHub(),
|
||||
clients: clients.New(),
|
||||
terminals: newTerminals(),
|
||||
startedAt: time.Now().UTC(),
|
||||
users: map[string]string{},
|
||||
}
|
||||
s.clients = clients.New(s.clientsChanged)
|
||||
|
||||
s.store, err = store.Open(filepath.Join(dataDir, "byre.db"), portFirst, s.publish)
|
||||
if err != nil {
|
||||
@@ -145,11 +145,26 @@ func (s *Server) identify(next http.Handler) http.Handler {
|
||||
}
|
||||
|
||||
func (s *Server) acted(login string, r *http.Request) {
|
||||
if s.hub.acted(login, r.Header.Get("Byre-Host"), r.Header.Get("Byre-Commit")) {
|
||||
if s.clients.Acted(r.Header.Get("Byre-Client"), login, r.Header.Get("Byre-Host"), r.Header.Get("Byre-Commit")) {
|
||||
s.clientsChanged()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) connectedClients() []api.ConnectedClient {
|
||||
out := []api.ConnectedClient{}
|
||||
for _, c := range s.clients.List() {
|
||||
out = append(out, api.ConnectedClient{
|
||||
Id: c.ID,
|
||||
Login: c.Login,
|
||||
Host: c.Host,
|
||||
Commit: c.Commit,
|
||||
ConnectedAt: c.ConnectedAt,
|
||||
LastActionAt: c.LastActionAt,
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *Server) clientsChanged() {
|
||||
s.store.Broadcast(api.Event{Kind: "admin.clients", Actor: "byre", Payload: map[string]any{}})
|
||||
}
|
||||
@@ -638,7 +653,7 @@ func (s *Server) status(ctx context.Context) (api.Status, error) {
|
||||
Projects: c.Projects,
|
||||
ActiveTasks: c.ActiveTasks,
|
||||
SseClients: s.hub.count(),
|
||||
Clients: s.hub.clients(),
|
||||
Clients: s.connectedClients(),
|
||||
LiveAgents: s.agents.LiveCount(),
|
||||
RunningTurns: usage.Running,
|
||||
RateLimits: usage.RateLimits,
|
||||
|
||||
Reference in New Issue
Block a user