Skip to content

Commit

Permalink
feat: improve task runner environment configuration
Browse files Browse the repository at this point in the history
- Remove Crawlab-specific environment variables from the task runner's environment
- Automatically create workspace directory if it doesn't exist
- Enhance environment setup to prevent potential configuration conflicts
  • Loading branch information
Marvin Zhang committed Feb 14, 2025
1 parent 4317a03 commit 6718170
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/task/handler/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,16 @@ func (r *Runner) configureEnv() {

// Default envs
r.cmd.Env = os.Environ()

// Remove CRAWLAB_ prefixed environment variables
for i := 0; i < len(r.cmd.Env); i++ {
if strings.HasPrefix(r.cmd.Env[i], "CRAWLAB_") {
r.cmd.Env = append(r.cmd.Env[:i], r.cmd.Env[i+1:]...)
i--
}
}

// Task-specific environment variables
r.cmd.Env = append(r.cmd.Env, "CRAWLAB_TASK_ID="+r.tid.Hex())

// Global environment variables
Expand Down
7 changes: 7 additions & 0 deletions core/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
"os"
"path/filepath"
"strings"
)
Expand Down Expand Up @@ -93,6 +94,12 @@ func GetWorkspace() string {
if res := viper.GetString("workspace"); res != "" {
return res
}
if !Exists(filepath.Join(homedirPath, DefaultWorkspace)) {
err := os.MkdirAll(filepath.Join(homedirPath, DefaultWorkspace), os.ModePerm)
if err != nil {
logger.Warnf("cannot create workspace directory: %v", err)
}
}
return filepath.Join(homedirPath, DefaultWorkspace)
}

Expand Down

0 comments on commit 6718170

Please sign in to comment.