本文整理汇总了Golang中github.com/juju/juju/core/migration.Phase.IsTerminal方法的典型用法代码示例。如果您正苦于以下问题:Golang Phase.IsTerminal方法的具体用法?Golang Phase.IsTerminal怎么用?Golang Phase.IsTerminal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/core/migration.Phase
的用法示例。
在下文中一共展示了Phase.IsTerminal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetPhase
// SetPhase implements ModelMigration.
func (mig *modelMigration) SetPhase(nextPhase migration.Phase) error {
now := GetClock().Now().UnixNano()
phase, err := mig.Phase()
if err != nil {
return errors.Trace(err)
}
if nextPhase == phase {
return nil // Already at that phase. Nothing to do.
}
if !phase.CanTransitionTo(nextPhase) {
return errors.Errorf("illegal phase change: %s -> %s", phase, nextPhase)
}
nextDoc := mig.statusDoc
nextDoc.Phase = nextPhase.String()
nextDoc.PhaseChangedTime = now
update := bson.M{
"phase": nextDoc.Phase,
"phase-changed-time": now,
}
if nextPhase == migration.SUCCESS {
nextDoc.SuccessTime = now
update["success-time"] = now
}
var ops []txn.Op
if nextPhase.IsTerminal() {
nextDoc.EndTime = now
update["end-time"] = now
ops = append(ops, txn.Op{
C: migrationsActiveC,
Id: mig.doc.ModelUUID,
Assert: txn.DocExists,
Remove: true,
})
}
ops = append(ops, txn.Op{
C: migrationsStatusC,
Id: mig.statusDoc.Id,
Update: bson.M{"$set": update},
// Ensure phase hasn't changed underneath us
Assert: bson.M{"phase": mig.statusDoc.Phase},
})
if err := mig.st.runTransaction(ops); err == txn.ErrAborted {
return errors.New("phase already changed")
} else if err != nil {
return errors.Annotate(err, "failed to update phase")
}
mig.statusDoc = nextDoc
return nil
}
示例2: IsTerminal
// IsTerminal returns true when the given phase means a migration has
// finished (successfully or otherwise).
func IsTerminal(phase migration.Phase) bool {
return phase.IsTerminal()
}