本文整理匯總了Golang中code/cloudfoundry/org/bbs/models.Task.ValidateTransitionTo方法的典型用法代碼示例。如果您正苦於以下問題:Golang Task.ValidateTransitionTo方法的具體用法?Golang Task.ValidateTransitionTo怎麽用?Golang Task.ValidateTransitionTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/cloudfoundry/org/bbs/models.Task
的用法示例。
在下文中一共展示了Task.ValidateTransitionTo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FailTask
func (db *SQLDB) FailTask(logger lager.Logger, taskGuid, failureReason string) (*models.Task, error) {
logger = logger.Session("fail-task", lager.Data{"task_guid": taskGuid})
logger.Info("starting")
defer logger.Info("complete")
var task *models.Task
err := db.transact(logger, func(logger lager.Logger, tx *sql.Tx) error {
var err error
task, err = db.fetchTaskForUpdate(logger, taskGuid, tx)
if err != nil {
logger.Error("failed-locking-task", err)
return err
}
if err = task.ValidateTransitionTo(models.Task_Completed); err != nil {
if task.State != models.Task_Pending {
logger.Error("failed-to-transition-task-to-completed", err)
return err
}
}
return db.completeTask(logger, task, true, failureReason, "", tx)
})
return task, err
}
示例2: CompleteTask
func (db *SQLDB) CompleteTask(logger lager.Logger, taskGuid, cellID string, failed bool, failureReason, taskResult string) (*models.Task, error) {
logger = logger.Session("complete-task", lager.Data{"task_guid": taskGuid, "cell_id": cellID})
logger.Info("starting")
defer logger.Info("complete")
var task *models.Task
err := db.transact(logger, func(logger lager.Logger, tx *sql.Tx) error {
var err error
task, err = db.fetchTaskForUpdate(logger, taskGuid, tx)
if err != nil {
logger.Error("failed-locking-task", err)
return err
}
if task.CellId != cellID && task.State == models.Task_Running {
logger.Error("failed-task-already-running-on-different-cell", err)
return models.NewRunningOnDifferentCellError(cellID, task.CellId)
}
if err = task.ValidateTransitionTo(models.Task_Completed); err != nil {
logger.Error("failed-to-transition-task-to-completed", err)
return err
}
return db.completeTask(logger, task, failed, failureReason, taskResult, tx)
})
return task, err
}