1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
11 "git.arvados.org/arvados.git/lib/cmd"
12 "git.arvados.org/arvados.git/lib/service"
13 "git.arvados.org/arvados.git/sdk/go/arvados"
14 "git.arvados.org/arvados.git/sdk/go/ctxlog"
15 "github.com/prometheus/client_golang/prometheus"
20 var Command cmd.Handler = service.Command(arvados.ServiceNameWebsocket, newHandler)
22 func newHandler(ctx context.Context, cluster *arvados.Cluster, token string, reg *prometheus.Registry) service.Handler {
23 client, err := arvados.NewClientFromConfig(cluster)
25 return service.ErrorHandler(ctx, cluster, fmt.Errorf("error initializing client from cluster config: %s", err))
27 eventSource := &pgEventSource{
28 DataSource: cluster.PostgreSQL.Connection.String(),
29 MaxOpenConns: cluster.PostgreSQL.ConnectionPool,
30 QueueSize: cluster.API.WebsocketServerEventQueue,
31 Logger: ctxlog.FromContext(ctx),
34 done := make(chan struct{})
37 ctxlog.FromContext(ctx).Error("event source stopped")
40 eventSource.WaitReady()
41 if err := eventSource.DBHealth(); err != nil {
42 return service.ErrorHandler(ctx, cluster, err)
47 eventSource: eventSource,
48 newPermChecker: func() permChecker { return newPermChecker(*client) },