-
Notifications
You must be signed in to change notification settings - Fork 628
/
session.go
72 lines (61 loc) 路 1.51 KB
/
session.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
67
68
69
70
71
72
package gowandb
import (
"context"
"fmt"
"github.com/wandb/wandb/nexus/internal/execbin"
"github.com/wandb/wandb/nexus/internal/launcher"
"github.com/wandb/wandb/nexus/pkg/gowandb/opts/runopts"
"github.com/wandb/wandb/nexus/pkg/gowandb/opts/sessionopts"
"github.com/wandb/wandb/nexus/pkg/gowandb/settings"
)
type Session struct {
manager *Manager
execCmd *execbin.ForkExecCmd
// embed settings parameters which are set by sessionopts options
sessionopts.SessionParams
}
func (s *Session) start() {
var execCmd *execbin.ForkExecCmd
var err error
ctx := context.Background()
sessionSettings := s.Settings
if sessionSettings == nil {
sessionSettings = settings.NewSettings()
}
if s.Address == "" {
launch := launcher.NewLauncher()
if len(s.CoreBinary) != 0 {
execCmd, err = launch.LaunchBinary(s.CoreBinary)
} else {
execCmd, err = launch.LaunchCommand("nexus")
}
if err != nil {
panic("error launching")
}
s.execCmd = execCmd
port, err := launch.Getport()
if err != nil {
panic("error getting port")
}
s.Address = fmt.Sprintf("127.0.0.1:%d", port)
}
s.manager = NewManager(ctx, sessionSettings, s.Address)
}
func (s *Session) Close() {
s.manager.Close()
if s.execCmd != nil {
_ = s.execCmd.Wait()
// TODO(beta): check exit code
}
}
func (s *Session) NewRun(opts ...runopts.RunOption) (*Run, error) {
runParams := &runopts.RunParams{}
for _, opt := range opts {
opt(runParams)
}
run := s.manager.NewRun(runParams)
run.setup()
run.init()
run.start()
return run, nil
}