File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -2,15 +2,17 @@ package cli
2
2
3
3
import (
4
4
"context"
5
+ "time"
5
6
6
7
cliContext "github.com/mudler/LocalAI/core/cli/context"
7
8
"github.com/mudler/LocalAI/core/explorer"
8
9
"github.com/mudler/LocalAI/core/http"
9
10
)
10
11
11
12
type ExplorerCMD struct {
12
- Address string `env:"LOCALAI_ADDRESS,ADDRESS" default:":8080" help:"Bind address for the API server" group:"api"`
13
- PoolDatabase string `env:"LOCALAI_POOL_DATABASE,POOL_DATABASE" default:"explorer.json" help:"Path to the pool database" group:"api"`
13
+ Address string `env:"LOCALAI_ADDRESS,ADDRESS" default:":8080" help:"Bind address for the API server" group:"api"`
14
+ PoolDatabase string `env:"LOCALAI_POOL_DATABASE,POOL_DATABASE" default:"explorer.json" help:"Path to the pool database" group:"api"`
15
+ ConnectionTimeout string `env:"LOCALAI_CONNECTION_TIMEOUT,CONNECTION_TIMEOUT" default:"2m" help:"Connection timeout for the explorer" group:"api"`
14
16
}
15
17
16
18
func (e * ExplorerCMD ) Run (ctx * cliContext.Context ) error {
@@ -20,7 +22,11 @@ func (e *ExplorerCMD) Run(ctx *cliContext.Context) error {
20
22
return err
21
23
}
22
24
23
- ds := explorer .NewDiscoveryServer (db )
25
+ dur , err := time .ParseDuration (e .ConnectionTimeout )
26
+ if err != nil {
27
+ return err
28
+ }
29
+ ds := explorer .NewDiscoveryServer (db , dur )
24
30
25
31
go ds .Start (context .Background ())
26
32
appHTTP := http .Explorer (db , ds )
Original file line number Diff line number Diff line change @@ -13,8 +13,9 @@ import (
13
13
14
14
type DiscoveryServer struct {
15
15
sync.Mutex
16
- database * Database
17
- networkState * NetworkState
16
+ database * Database
17
+ networkState * NetworkState
18
+ connectionTime time.Duration
18
19
}
19
20
20
21
type NetworkState struct {
@@ -29,9 +30,13 @@ func (s *DiscoveryServer) NetworkState() *NetworkState {
29
30
30
31
// NewDiscoveryServer creates a new DiscoveryServer with the given Database.
31
32
// it keeps the db state in sync with the network state
32
- func NewDiscoveryServer (db * Database ) * DiscoveryServer {
33
+ func NewDiscoveryServer (db * Database , dur time.Duration ) * DiscoveryServer {
34
+ if dur == 0 {
35
+ dur = 50 * time .Second
36
+ }
33
37
return & DiscoveryServer {
34
- database : db ,
38
+ database : db ,
39
+ connectionTime : dur ,
35
40
networkState : & NetworkState {
36
41
Networks : map [string ]Network {},
37
42
},
@@ -49,7 +54,7 @@ func (s *DiscoveryServer) runBackground() {
49
54
}
50
55
51
56
for _ , token := range s .database .TokenList () {
52
- c , cancel := context .WithTimeout (context .Background (), 50 * time . Second )
57
+ c , cancel := context .WithTimeout (context .Background (), s . connectionTime )
53
58
defer cancel ()
54
59
55
60
// Connect to the network
You can’t perform that action at this time.
0 commit comments