alt/services/worker/internal/socket/server.go
toki ec938475e0 chore: socket rail implementation and task archival
- Add backtest and market socket handlers for API and Worker
- Add proto definitions for backtest and market services
- Update client socket integration and tests
- Generate protobuf code for Go and Dart
- Archive completed agent tasks under agent-task/archive/2026/05/
2026-05-30 22:57:18 +09:00

39 lines
952 B
Go

package socket
import (
"context"
protoSocket "git.toki-labs.com/toki/proto-socket/go"
"nhooyr.io/websocket"
"git.toki-labs.com/toki/alt/services/worker/internal/config"
workerContracts "git.toki-labs.com/toki/alt/services/worker/internal/contracts"
)
const (
serverName = "alt-worker"
serverVersion = "dev"
defaultAltProtocolVersion = "alt.v1"
)
type Server struct {
wsServer *protoSocket.WsServer
}
func NewServer(cfg config.Config, deps Deps) *Server {
wsServer := protoSocket.NewWsServer(cfg.Host, cfg.Port, cfg.SocketPath, func(conn *websocket.Conn) *protoSocket.WsClient {
return protoSocket.NewWsClient(conn, 30, 10, workerContracts.ParserMap())
})
wsServer.OnClientConnected = registerSessionHandlers(deps)
return &Server{
wsServer: wsServer,
}
}
func (s *Server) Start(ctx context.Context) error {
return s.wsServer.Start(ctx)
}
func (s *Server) Stop() error {
return s.wsServer.Stop()
}