本文整理匯總了Golang中code/cloudfoundry/org/bbs/models.ActualLRP.ShouldRestartImmediately方法的典型用法代碼示例。如果您正苦於以下問題:Golang ActualLRP.ShouldRestartImmediately方法的具體用法?Golang ActualLRP.ShouldRestartImmediately怎麽用?Golang ActualLRP.ShouldRestartImmediately使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/cloudfoundry/org/bbs/models.ActualLRP
的用法示例。
在下文中一共展示了ActualLRP.ShouldRestartImmediately方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}