[minor] Mark and ignore bad files in mig-scheduler. Fixes #131.

This commit is contained in:
Jose Diez 2015-10-19 14:46:47 +01:00
Родитель 3cfb4a4220
Коммит 74fdb1c923
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