mirror of
https://github.com/go-task/task.git
synced 2025-06-27 00:51:05 +02:00
cache dymanic variables
This commit is contained in:
8
task.go
8
task.go
@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/go-task/task/execext"
|
"github.com/go-task/task/execext"
|
||||||
|
|
||||||
@ -33,6 +34,9 @@ type Executor struct {
|
|||||||
|
|
||||||
taskvars Vars
|
taskvars Vars
|
||||||
watchingFiles map[string]struct{}
|
watchingFiles map[string]struct{}
|
||||||
|
|
||||||
|
dynamicCache Vars
|
||||||
|
muDynamicCache sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vars is a string[string] variables map
|
// Vars is a string[string] variables map
|
||||||
@ -71,6 +75,10 @@ func (e *Executor) Run(args ...string) error {
|
|||||||
e.Stderr = os.Stderr
|
e.Stderr = os.Stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if e.dynamicCache == nil {
|
||||||
|
e.dynamicCache = make(Vars, 10)
|
||||||
|
}
|
||||||
|
|
||||||
// check if given tasks exist
|
// check if given tasks exist
|
||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
if _, ok := e.Tasks[a]; !ok {
|
if _, ok := e.Tasks[a]; !ok {
|
||||||
|
@ -26,6 +26,12 @@ func (e *Executor) handleDynamicVariableContent(value string) (string, error) {
|
|||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e.muDynamicCache.Lock()
|
||||||
|
defer e.muDynamicCache.Unlock()
|
||||||
|
if result, ok := e.dynamicCache[value]; ok {
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
buff := bytes.NewBuffer(nil)
|
buff := bytes.NewBuffer(nil)
|
||||||
|
|
||||||
opts := &execext.RunCommandOptions{
|
opts := &execext.RunCommandOptions{
|
||||||
@ -46,6 +52,7 @@ func (e *Executor) handleDynamicVariableContent(value string) (string, error) {
|
|||||||
|
|
||||||
result = strings.TrimSpace(result)
|
result = strings.TrimSpace(result)
|
||||||
e.verbosePrintfln(`task: dynamic variable: "%s", result: "%s"`, value, result)
|
e.verbosePrintfln(`task: dynamic variable: "%s", result: "%s"`, value, result)
|
||||||
|
e.dynamicCache[value] = result
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user