本文整理匯總了Golang中code/cloudfoundry/org/bbs/models.ActualLRP.CrashCount方法的典型用法代碼示例。如果您正苦於以下問題:Golang ActualLRP.CrashCount方法的具體用法?Golang ActualLRP.CrashCount怎麽用?Golang ActualLRP.CrashCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/cloudfoundry/org/bbs/models.ActualLRP
的用法示例。
在下文中一共展示了ActualLRP.CrashCount方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Evacuation", func() {
var (
actualLRP *models.ActualLRP
guid string
index int32
)
BeforeEach(func() {
guid = "some-guid"
index = int32(1)
actualLRP = model_helpers.NewValidActualLRP(guid, index)
actualLRP.CrashCount = 0
actualLRP.CrashReason = ""
actualLRP.Since = fakeClock.Now().UnixNano()
actualLRP.ModificationTag = models.ModificationTag{}
actualLRP.ModificationTag.Increment()
actualLRP.ModificationTag.Increment()
_, err := sqlDB.CreateUnclaimedActualLRP(logger, &actualLRP.ActualLRPKey)
Expect(err).NotTo(HaveOccurred())
_, _, err = sqlDB.ClaimActualLRP(logger, guid, index, &actualLRP.ActualLRPInstanceKey)
Expect(err).NotTo(HaveOccurred())
_, _, err = sqlDB.StartActualLRP(logger, &actualLRP.ActualLRPKey, &actualLRP.ActualLRPInstanceKey, &actualLRP.ActualLRPNetInfo)
Expect(err).NotTo(HaveOccurred())
})
Describe("EvacuateActualLRP", func() {
示例2: CrashActualLRP
func (db *SQLDB) CrashActualLRP(logger lager.Logger, key *models.ActualLRPKey, instanceKey *models.ActualLRPInstanceKey, crashReason string) (*models.ActualLRPGroup, *models.ActualLRPGroup, bool, error) {
logger = logger.WithData(lager.Data{"key": key, "instance_key": instanceKey, "crash_reason": crashReason})
logger.Info("starting")
defer logger.Info("complete")
var immediateRestart = false
var beforeActualLRP models.ActualLRP
var actualLRP *models.ActualLRP
err := db.transact(logger, func(logger lager.Logger, tx *sql.Tx) error {
var err error
actualLRP, err = db.fetchActualLRPForUpdate(logger, key.ProcessGuid, key.Index, false, tx)
if err != nil {
logger.Error("failed-to-get-actual-lrp", err)
return err
}
beforeActualLRP = *actualLRP
latestChangeTime := time.Duration(db.clock.Now().UnixNano() - actualLRP.Since)
var newCrashCount int32
if latestChangeTime > models.CrashResetTimeout && actualLRP.State == models.ActualLRPStateRunning {
newCrashCount = 1
} else {
newCrashCount = actualLRP.CrashCount + 1
}
if !actualLRP.AllowsTransitionTo(&actualLRP.ActualLRPKey, instanceKey, models.ActualLRPStateCrashed) {
logger.Error("failed-to-transition-to-crashed", nil, lager.Data{"from_state": actualLRP.State, "same_instance_key": actualLRP.ActualLRPInstanceKey.Equal(instanceKey)})
return models.ErrActualLRPCannotBeCrashed
}
actualLRP.ModificationTag.Increment()
actualLRP.State = models.ActualLRPStateCrashed
actualLRP.ActualLRPInstanceKey.InstanceGuid = ""
actualLRP.ActualLRPInstanceKey.CellId = ""
actualLRP.ActualLRPNetInfo = models.ActualLRPNetInfo{}
actualLRP.CrashCount = newCrashCount
actualLRP.CrashReason = crashReason
evacuating := false
if actualLRP.ShouldRestartImmediately(models.NewDefaultRestartCalculator()) {
actualLRP.State = models.ActualLRPStateUnclaimed
immediateRestart = true
}
now := db.clock.Now().UnixNano()
actualLRP.Since = now
_, err = db.update(logger, tx, actualLRPsTable,
SQLAttributes{
"state": actualLRP.State,
"cell_id": actualLRP.CellId,
"instance_guid": actualLRP.InstanceGuid,
"modification_tag_index": actualLRP.ModificationTag.Index,
"crash_count": actualLRP.CrashCount,
"crash_reason": truncateString(actualLRP.CrashReason, 1024),
"since": actualLRP.Since,
"net_info": []byte{},
},
"process_guid = ? AND instance_index = ? AND evacuating = ?",
key.ProcessGuid, key.Index, evacuating,
)
if err != nil {
logger.Error("failed-to-crash-actual-lrp", err)
return db.convertSQLError(err)
}
return nil
})
return &models.ActualLRPGroup{Instance: &beforeActualLRP}, &models.ActualLRPGroup{Instance: actualLRP}, immediateRestart, err
}