зеркало из https://github.com/mozilla/mig.git
[minor] Mark and ignore bad files in mig-scheduler. Fixes #131.
This commit is contained in:
Родитель
3cfb4a4220
Коммит
74fdb1c923
|
@ -10,6 +10,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"mig.ninja/mig"
|
"mig.ninja/mig"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -134,6 +135,12 @@ func loadReturnedCommands(ctx Context) (err error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
filename := ctx.Directories.Command.Returned + "/" + DirEntry.Name()
|
filename := ctx.Directories.Command.Returned + "/" + DirEntry.Name()
|
||||||
|
|
||||||
|
if strings.HasSuffix(filename, ".fail") {
|
||||||
|
// skip files with invalid commands
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
_, err = os.Stat(filename)
|
_, err = os.Stat(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// file is already gone, probably consumed by the file notifier
|
// 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.
|
// load and parse the command. If this fail, skip it and continue.
|
||||||
cmd, err := mig.CmdFromFile(cmdFile)
|
cmd, err := mig.CmdFromFile(cmdFile)
|
||||||
if err != nil {
|
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()
|
cmd.FinishTime = time.Now().UTC()
|
||||||
// update command in database
|
// update command in database
|
||||||
|
|
Загрузка…
Ссылка в новой задаче