mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 02:24:59 +00:00
feat(explorer): make possible to run sync in a separate process (#3224)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
4dfa085339
commit
9729d2ae37
9 changed files with 83 additions and 67 deletions
|
@ -14,6 +14,9 @@ type ExplorerCMD struct {
|
|||
PoolDatabase string `env:"LOCALAI_POOL_DATABASE,POOL_DATABASE" default:"explorer.json" help:"Path to the pool database" group:"api"`
|
||||
ConnectionTimeout string `env:"LOCALAI_CONNECTION_TIMEOUT,CONNECTION_TIMEOUT" default:"2m" help:"Connection timeout for the explorer" group:"api"`
|
||||
ConnectionErrorThreshold int `env:"LOCALAI_CONNECTION_ERROR_THRESHOLD,CONNECTION_ERROR_THRESHOLD" default:"3" help:"Connection failure threshold for the explorer" group:"api"`
|
||||
|
||||
WithSync bool `env:"LOCALAI_WITH_SYNC,WITH_SYNC" default:"false" help:"Enable sync with the network" group:"api"`
|
||||
OnlySync bool `env:"LOCALAI_ONLY_SYNC,ONLY_SYNC" default:"false" help:"Only sync with the network" group:"api"`
|
||||
}
|
||||
|
||||
func (e *ExplorerCMD) Run(ctx *cliContext.Context) error {
|
||||
|
@ -27,10 +30,20 @@ func (e *ExplorerCMD) Run(ctx *cliContext.Context) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ds := explorer.NewDiscoveryServer(db, dur, e.ConnectionErrorThreshold)
|
||||
|
||||
go ds.Start(context.Background())
|
||||
appHTTP := http.Explorer(db, ds)
|
||||
if e.WithSync {
|
||||
ds := explorer.NewDiscoveryServer(db, dur, e.ConnectionErrorThreshold)
|
||||
go ds.Start(context.Background(), true)
|
||||
}
|
||||
|
||||
if e.OnlySync {
|
||||
ds := explorer.NewDiscoveryServer(db, dur, e.ConnectionErrorThreshold)
|
||||
ctx := context.Background()
|
||||
|
||||
return ds.Start(ctx, false)
|
||||
}
|
||||
|
||||
appHTTP := http.Explorer(db)
|
||||
|
||||
return appHTTP.Listen(e.Address)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue