Skip to content

Commit

Permalink
Merge pull request #7 from cloudradar-monitoring/DEV-2369
Browse files Browse the repository at this point in the history
fix file.managed
  • Loading branch information
martinlindhe authored Nov 2, 2021
2 parents 4b653a3 + df2561f commit fede347
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
15 changes: 8 additions & 7 deletions script/scriptResult.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type taskResult struct {
Name string `yaml:"Name"`
Result bool `yaml:"Result"`
Comment string `yaml:"Comment,omitempty"`
Error string `yaml:"Error,omitempty"`

Started onlyTime `yaml:"Started"`
Duration time.Duration `yaml:"Duration"`
Expand All @@ -24,13 +25,13 @@ type taskResult struct {
}

type scriptSummary struct {
Config string `yaml:"Config"`
Succeeded int `yaml:"Succeeded"`
Failed int `yaml:"Failed"`
Aborted int `yaml:"Aborted"`
Changes int `yaml:"Changes"`
TotalFunctionsRun int `yaml:"TotalFunctionsRun"`
TotalRunTime time.Duration `yaml:"TotalRunTime"`
Script string `yaml:"Script"`
Succeeded int `yaml:"Succeeded"`
Failed int `yaml:"Failed"`
Aborted int `yaml:"Aborted"`
Changes int `yaml:"Changes"`
TotalTasksRun int `yaml:"TotalTasksRun"`
TotalRunTime time.Duration `yaml:"TotalRunTime"`
}

const stampMicro = "15:04:05.000000"
Expand Down
19 changes: 12 additions & 7 deletions script/scriptRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (r Runner) Run(ctx context.Context, scripts tasks.Scripts, globalAbortOnErr
}
}

errString := ""
if res.Err != nil {
errString = res.Err.Error()
}
result.Results = append(result.Results, taskResult{
ID: script.ID,
Function: task.GetName(),
Expand All @@ -98,6 +102,7 @@ func (r Runner) Run(ctx context.Context, scripts tasks.Scripts, globalAbortOnErr
Started: onlyTime(taskStart),
Duration: res.Duration,
Changes: changeMap,
Error: errString,
})
}

Expand All @@ -110,13 +115,13 @@ func (r Runner) Run(ctx context.Context, scripts tasks.Scripts, globalAbortOnErr
}

result.Summary = scriptSummary{
Config: r.DataProvider.Path,
Succeeded: succeeded,
Failed: failed,
Aborted: aborted,
Changes: changes,
TotalFunctionsRun: tasksRun,
TotalRunTime: time.Since(scriptStart),
Script: r.DataProvider.Path,
Succeeded: succeeded,
Failed: failed,
Aborted: aborted,
Changes: changes,
TotalTasksRun: tasksRun,
TotalRunTime: time.Since(scriptStart),
}

y, err := yaml.Marshal(result)
Expand Down
3 changes: 3 additions & 0 deletions tasks/fileManagedTask.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ func (fmte *FileManagedTaskExecutor) Execute(ctx context.Context, task Task) Exe
return execRes
}

execRes.Name = fileManagedTask.Name

var stdoutBuf, stderrBuf bytes.Buffer
execCtx := &exec2.Context{
Ctx: ctx,
Expand Down Expand Up @@ -366,6 +368,7 @@ func (fmte *FileManagedTaskExecutor) checkMissingFileCondition(
fileManagedTask *FileManagedTask,
) (isExists bool, fileName string, err error) {
if len(fileManagedTask.Creates) == 0 {
fileName = fileManagedTask.Name
return
}

Expand Down
7 changes: 2 additions & 5 deletions utils/osFilesWin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
package utils

import (
"fmt"
"os"
"strings"

log "github.com/sirupsen/logrus"
)

func ParseLocationOS(rawLocation string) string {
Expand All @@ -22,7 +21,5 @@ func ParseLocationOS(rawLocation string) string {
}

func Chown(targetFilePath, userName, groupName string) error {
log.Debug("no chown support under windows")

return nil
return fmt.Errorf("no chown support under windows")
}

0 comments on commit fede347

Please sign in to comment.