本文整理汇总了Golang中mig.Command.FinishTime方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.FinishTime方法的具体用法?Golang Command.FinishTime怎么用?Golang Command.FinishTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mig.Command
的用法示例。
在下文中一共展示了Command.FinishTime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: terminateCommand
// terminateCommand is called when a command result is dropped into ctx.Directories.Command.Returned
// it stores the result of a command and mark it as completed/failed and then
// send a message to the Action completion routine to update the action status
func terminateCommand(cmdPath string, ctx Context) (err error) {
var cmd mig.Command
defer func() {
if e := recover(); e != nil {
err = fmt.Errorf("terminateCommand() -> %v", e)
}
ctx.Channels.Log <- mig.Log{OpID: ctx.OpID, ActionID: cmd.Action.ID, CommandID: cmd.ID, Desc: "leaving terminateCommand()"}.Debug()
}()
// load and parse the command. If this fail, skip it and continue.
cmd, err = mig.CmdFromFile(cmdPath)
if err != nil {
panic(err)
}
cmd.FinishTime = time.Now().UTC()
// update command in database
err = ctx.DB.Col.Cmd.Update(bson.M{"id": cmd.ID}, cmd)
if err != nil {
panic(err)
}
ctx.Channels.Log <- mig.Log{OpID: ctx.OpID, ActionID: cmd.Action.ID, CommandID: cmd.ID, Desc: "command updated in database"}.Debug()
// write to disk to Command Done directory
data, err := json.Marshal(cmd)
if err != nil {
panic(err)
}
dest := fmt.Sprintf("%s/%d-%d.json", ctx.Directories.Command.Done, cmd.Action.ID, cmd.ID)
err = safeWrite(ctx, dest, data)
if err != nil {
panic(err)
}
// remove command from inflight dir
inflightPath := fmt.Sprintf("%s/%d-%d.json", ctx.Directories.Command.InFlight, cmd.Action.ID, cmd.ID)
os.Remove(inflightPath)
// remove command from Returned dir
os.Remove(cmdPath)
return
}