本文整理匯總了Golang中code/cloudfoundry/org/bbs/models.Task.Validate方法的典型用法代碼示例。如果您正苦於以下問題:Golang Task.Validate方法的具體用法?Golang Task.Validate怎麽用?Golang Task.Validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/cloudfoundry/org/bbs/models.Task
的用法示例。
在下文中一共展示了Task.Validate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ConvergeTasks
func (db *ETCDDB) ConvergeTasks(
logger lager.Logger,
cellSet models.CellSet,
kickTaskDuration, expirePendingTaskDuration, expireCompletedTaskDuration time.Duration,
) ([]*auctioneer.TaskStartRequest, []*models.Task) {
logger.Info("starting-convergence")
defer logger.Info("finished-convergence")
convergeTaskRunsCounter.Increment()
convergeStart := db.clock.Now()
defer func() {
err := convergeTaskDuration.Send(time.Since(convergeStart))
if err != nil {
logger.Error("failed-to-send-converge-task-duration-metric", err)
}
}()
logger.Debug("listing-tasks")
taskState, modelErr := db.fetchRecursiveRaw(logger, TaskSchemaRoot)
if modelErr != nil {
logger.Debug("failed-listing-task")
sendTaskMetrics(logger, -1, -1, -1, -1)
return nil, nil
}
logger.Debug("succeeded-listing-task")
logError := func(task *models.Task, message string) {
logger.Error(message, nil, lager.Data{
"task_guid": task.TaskGuid,
})
}
tasksToComplete := []*models.Task{}
scheduleForCompletion := func(task *models.Task) {
if task.CompletionCallbackUrl == "" {
return
}
tasksToComplete = append(tasksToComplete, task)
}
keysToDelete := []string{}
tasksToCAS := []compareAndSwappableTask{}
scheduleForCASByIndex := func(index uint64, newTask *models.Task) {
tasksToCAS = append(tasksToCAS, compareAndSwappableTask{
OldIndex: index,
NewTask: newTask,
})
}
tasksToAuction := []*auctioneer.TaskStartRequest{}
var tasksKicked uint64 = 0
pendingCount := 0
runningCount := 0
completedCount := 0
resolvingCount := 0
logger.Debug("determining-convergence-work", lager.Data{"num_tasks": len(taskState.Nodes)})
for _, node := range taskState.Nodes {
task := new(models.Task)
err := db.deserializeModel(logger, node, task)
if err != nil || task.Validate() != nil {
logger.Error("found-invalid-task", err, lager.Data{
"key": node.Key,
"value": node.Value,
})
keysToDelete = append(keysToDelete, node.Key)
continue
}
shouldKickTask := db.durationSinceTaskUpdated(task) >= kickTaskDuration
switch task.State {
case models.Task_Pending:
pendingCount++
shouldMarkAsFailed := db.durationSinceTaskCreated(task) >= expirePendingTaskDuration
if shouldMarkAsFailed {
logError(task, "failed-to-start-in-time")
db.markTaskFailed(task, "not started within time limit")
scheduleForCASByIndex(node.ModifiedIndex, task)
tasksKicked++
} else if shouldKickTask {
logger.Info("requesting-auction-for-pending-task", lager.Data{"task_guid": task.TaskGuid})
start := auctioneer.NewTaskStartRequestFromModel(task.TaskGuid, task.Domain, task.TaskDefinition)
tasksToAuction = append(tasksToAuction, &start)
tasksKicked++
}
case models.Task_Running:
runningCount++
cellIsAlive := cellSet.HasCellID(task.CellId)
if !cellIsAlive {
logError(task, "cell-disappeared")
db.markTaskFailed(task, "cell disappeared before completion")
scheduleForCASByIndex(node.ModifiedIndex, task)
tasksKicked++
//.........這裏部分代碼省略.........
示例2:
Describe("Validate", func() {
Context("when the task has a domain, valid guid, stack, and valid action", func() {
It("is valid", func() {
task = models.Task{
Domain: "some-domain",
TaskGuid: "some-task-guid",
TaskDefinition: &models.TaskDefinition{
RootFs: "some:rootfs",
Action: models.WrapAction(&models.RunAction{
Path: "ls",
User: "me",
}),
},
}
err := task.Validate()
Expect(err).NotTo(HaveOccurred())
})
})
Context("when the task GUID is present but invalid", func() {
It("returns an error indicating so", func() {
task = models.Task{
Domain: "some-domain",
TaskGuid: "invalid/guid",
TaskDefinition: &models.TaskDefinition{
RootFs: "some:rootfs",
Action: models.WrapAction(&models.RunAction{
Path: "ls",
User: "me",
}),