當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Phase.IsTerminal方法代碼示例

本文整理匯總了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
}
開發者ID:makyo,項目名稱:juju,代碼行數:56,代碼來源:modelmigration.go

示例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()
}
開發者ID:bac,項目名稱:juju,代碼行數:5,代碼來源:worker.go


注:本文中的github.com/juju/juju/core/migration.Phase.IsTerminal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。