-
Notifications
You must be signed in to change notification settings - Fork 632
/
manager.go
66 lines (57 loc) 路 1.67 KB
/
manager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package gowandb
import (
"context"
"github.com/wandb/wandb/nexus/internal/shared"
"github.com/wandb/wandb/nexus/pkg/gowandb/opts/runopts"
"github.com/wandb/wandb/nexus/pkg/gowandb/settings"
"github.com/wandb/wandb/nexus/pkg/service"
)
// Manager is a collection of components that work together to handle incoming
type Manager struct {
// ctx is the context for the run
ctx context.Context
// addr is the address of the server
addr string
// settings for all runs
settings *settings.SettingsWrap
}
// NewManager creates a new manager with the given settings and responders.
func NewManager(ctx context.Context, baseSettings *settings.SettingsWrap, addr string) *Manager {
manager := &Manager{
ctx: ctx,
settings: baseSettings,
addr: addr,
}
return manager
}
func (m *Manager) NewRun(runParams *runopts.RunParams) *Run {
conn := m.Connect(m.ctx)
// make a copy of the base manager settings
runSettings := m.settings.Copy()
if runParams.RunID != nil {
runSettings.SetRunID(*runParams.RunID)
} else if runSettings.RunId == nil {
runSettings.SetRunID(shared.ShortID(8))
}
run := NewRun(m.ctx, runSettings.Settings, conn, runParams)
return run
}
func (m *Manager) Connect(ctx context.Context) *Connection {
conn, err := NewConnection(ctx, m.addr)
// slog.Info("Connecting to server", "conn", conn.Conn.RemoteAddr().String())
if err != nil {
panic(err)
}
return conn
}
func (m *Manager) Close() {
conn := m.Connect(m.ctx)
serverRecord := service.ServerRequest{
ServerRequestType: &service.ServerRequest_InformTeardown{InformTeardown: &service.ServerInformTeardownRequest{}},
}
err := conn.Send(&serverRecord)
if err != nil {
return
}
conn.Close()
}