diff --git a/mig-scheduler/collector.go b/mig-scheduler/collector.go index d435bd5e..c1162a37 100644 --- a/mig-scheduler/collector.go +++ b/mig-scheduler/collector.go @@ -10,6 +10,7 @@ import ( "fmt" "mig.ninja/mig" "os" + "strings" "time" ) @@ -134,6 +135,12 @@ func loadReturnedCommands(ctx Context) (err error) { continue } filename := ctx.Directories.Command.Returned + "/" + DirEntry.Name() + + if strings.HasSuffix(filename, ".fail") { + // skip files with invalid commands + continue + } + _, err = os.Stat(filename) if err != nil { // file is already gone, probably consumed by the file notifier diff --git a/mig-scheduler/scheduler.go b/mig-scheduler/scheduler.go index 836414d5..5a24186d 100644 --- a/mig-scheduler/scheduler.go +++ b/mig-scheduler/scheduler.go @@ -248,7 +248,11 @@ func returnCommands(cmdFiles []string, ctx Context) (err error) { // load and parse the command. If this fail, skip it and continue. cmd, err := mig.CmdFromFile(cmdFile) if err != nil { - panic(err) + // if CmdFromFile fails, rename the cmdFile and skip. + desc := fmt.Sprintf("Command in %s failed, renaming to %s.fail", cmdFile, cmdFile) + ctx.Channels.Log <- mig.Log{OpID: ctx.OpID, Desc: desc}.Debug() + os.Rename(cmdFile, cmdFile+".fail") + continue } cmd.FinishTime = time.Now().UTC() // update command in database