本文整理汇总了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
}