diff --git a/internal/server/server.go b/internal/server/server.go index 04f1508..cfe3f2b 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -59,9 +59,15 @@ func initDependencies() { } log.Info("python dependencies sandbox initialized") - // start a ticker to update python dependencies every 30 minutes to keep the sandbox up-to-date + // start a ticker to update python dependencies to keep the sandbox up-to-date go func() { - ticker := time.NewTicker(30 * time.Minute) + updateInterval := static.GetDifySandboxGlobalConfigurations().PythonDepsUpdateInterval + tickerDuration, err := time.ParseDuration(updateInterval) + if err != nil { + log.Error("failed to parse python dependencies update interval, skip periodic updates: %v", err) + return + } + ticker := time.NewTicker(tickerDuration) for range ticker.C { if err:=updatePythonDependencies(dependencies);err!=nil{ log.Error("Failed to update Python dependencies: %v", err) diff --git a/internal/static/config.go b/internal/static/config.go index 580a22c..0f3401f 100644 --- a/internal/static/config.go +++ b/internal/static/config.go @@ -82,6 +82,17 @@ func InitConfig(path string) error { if python_pip_mirror_url != "" { difySandboxGlobalConfigurations.PythonPipMirrorURL = python_pip_mirror_url } + + python_deps_update_interval := os.Getenv("PYTHON_DEPS_UPDATE_INTERVAL") + if python_deps_update_interval != "" { + difySandboxGlobalConfigurations.PythonDepsUpdateInterval = python_deps_update_interval + } + + // if not set "PythonDepsUpdateInterval", update python dependencies every 30 minutes to keep the sandbox up-to-date + if difySandboxGlobalConfigurations.PythonDepsUpdateInterval == "" { + difySandboxGlobalConfigurations.PythonDepsUpdateInterval = "30m" + } + nodejs_path := os.Getenv("NODEJS_PATH") if nodejs_path != "" { difySandboxGlobalConfigurations.NodejsPath = nodejs_path diff --git a/internal/types/config.go b/internal/types/config.go index ab25069..a6854e2 100644 --- a/internal/types/config.go +++ b/internal/types/config.go @@ -6,16 +6,17 @@ type DifySandboxGlobalConfigurations struct { Debug bool `yaml:"debug"` Key string `yaml:"key"` } `yaml:"app"` - MaxWorkers int `yaml:"max_workers"` - MaxRequests int `yaml:"max_requests"` - WorkerTimeout int `yaml:"worker_timeout"` - PythonPath string `yaml:"python_path"` - PythonLibPaths []string `yaml:"python_lib_path"` - PythonPipMirrorURL string `yaml:"python_pip_mirror_url"` - NodejsPath string `yaml:"nodejs_path"` - EnableNetwork bool `yaml:"enable_network"` - AllowedSyscalls []int `yaml:"allowed_syscalls"` - Proxy struct { + MaxWorkers int `yaml:"max_workers"` + MaxRequests int `yaml:"max_requests"` + WorkerTimeout int `yaml:"worker_timeout"` + PythonPath string `yaml:"python_path"` + PythonLibPaths []string `yaml:"python_lib_path"` + PythonPipMirrorURL string `yaml:"python_pip_mirror_url"` + PythonDepsUpdateInterval string `yaml:"python_deps_update_interval"` + NodejsPath string `yaml:"nodejs_path"` + EnableNetwork bool `yaml:"enable_network"` + AllowedSyscalls []int `yaml:"allowed_syscalls"` + Proxy struct { Socks5 string `yaml:"socks5"` Https string `yaml:"https"` Http string `yaml:"http"`