Merge pull request #141 from jdiez17/fix131

[minor] Mark and ignore bad files in mig-scheduler. Fixes #131.
This commit is contained in:
Julien Vehent 2015-10-19 17:30:05 -04:00
Родитель 4f40587485 74fdb1c923
Коммит f316b3d752
2 изменённых файлов: 12 добавлений и 1 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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