Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: support for user-defined python dependencies update interval #85

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions internal/static/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions internal/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
Loading