当前位置: 首页>>代码示例>>Golang>>正文


Golang models.Task类代码示例

本文整理汇总了Golang中runtime-schema/models.Task的典型用法代码示例。如果您正苦于以下问题:Golang Task类的具体用法?Golang Task怎么用?Golang Task使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Task类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: resolveTask

func (handler *Handler) resolveTask(task *models.Task) {
	err := handler.bbs.ResolvingTask(task)
	if err != nil {
		logger.Info("handler.resolving-failed", map[string]interface{}{
			"task":  task.Guid,
			"error": err.Error(),
		})

		return
	}

	err = handler.natsClient.Publish(task.ReplyTo, task.ToJSON())
	if err != nil {
		logger.Error("handler.publish-failed", map[string]interface{}{
			"task":  task.Guid,
			"error": err.Error(),
		})

		return
	}

	err = handler.bbs.ResolveTask(task)
	if err != nil {
		logger.Error("handler.resolve-failed", map[string]interface{}{
			"task":  task.Guid,
			"error": err.Error(),
		})

		return
	}

	logger.Info("handler.resolved", map[string]interface{}{
		"task": task.Guid,
	})
}
开发者ID:vito,项目名称:fake-diego-release,代码行数:35,代码来源:handler.go

示例2: Complete

func (kicker *HurlerKicker) Complete(task *models.Task) {
	log.Println("kicking complete")

	json := task.ToJSON()

	res, err := http.DefaultClient.Do(&http.Request{
		Method: "POST",

		URL: &url.URL{
			Scheme: "http",
			Host:   kicker.hurlerAddress,
			Path:   "/tasks",
		},

		Host: "stager",

		Body:          ioutil.NopCloser(bytes.NewBuffer(json)),
		ContentLength: int64(len(json)),

		Header: map[string][]string{
			"Content-Type": []string{"application/json"},
		},
	})

	if err != nil {
		log.Println("kick complete error", err)
		return
	}

	log.Println("kick complete", res.Status)
}
开发者ID:vito,项目名称:fake-diego-release,代码行数:31,代码来源:hurler_kicker.go

示例3: CompleteTask

// The executor calls this when it has finished running the runonce (be it success or failure)
// stagerBBS will retry this repeatedly if it gets a StoreTimeout error (up to N seconds?)
// This really really shouldn't fail.  If it does, blog about it and walk away. If it failed in a
// consistent way (i.e. key already exists), there's probably a flaw in our design.
func (self *executorBBS) CompleteTask(task *models.Task, failed bool, failureReason string, result string) error {
	originalValue := task.ToJSON()

	task.UpdatedAt = self.timeProvider.Time().UnixNano()

	task.State = models.TaskStateCompleted
	task.Failed = failed
	task.FailureReason = failureReason
	task.Result = result

	return retryIndefinitelyOnStoreTimeout(func() error {
		err := self.store.CompareAndSwap(storeadapter.StoreNode{
			Key:   taskSchemaPath(task),
			Value: originalValue,
		}, storeadapter.StoreNode{
			Key:   taskSchemaPath(task),
			Value: task.ToJSON(),
		})
		if err != nil {
			return err
		}

		self.kicker.Complete(task)

		return nil
	})
}
开发者ID:vito,项目名称:fake-diego-release,代码行数:31,代码来源:executor_bbs.go

示例4: DesireTask

// The stager calls this when it wants to desire a payload
// stagerBBS will retry this repeatedly if it gets a StoreTimeout error (up to N seconds?)
// If this fails, the stager should bail and run its "this-failed-to-stage" routine
func (s *stagerBBS) DesireTask(task *models.Task) error {
	return retryIndefinitelyOnStoreTimeout(func() error {
		if task.CreatedAt == 0 {
			task.CreatedAt = s.timeProvider.Time().UnixNano()
		}

		task.UpdatedAt = s.timeProvider.Time().UnixNano()
		task.State = models.TaskStatePending

		err := s.store.SetMulti([]storeadapter.StoreNode{
			{
				Key:   taskSchemaPath(task),
				Value: task.ToJSON(),
			},
		})
		if err != nil {
			return err
		}

		s.kicker.Desire(task)

		return nil
	})
}
开发者ID:vito,项目名称:fake-diego-release,代码行数:27,代码来源:stager_bbs.go

示例5: StartTask

// The executor calls this when it is about to run the runonce in the claimed container
// stagerBBS will retry this repeatedly if it gets a StoreTimeout error (up to N seconds?)
// If this fails, the executor should assume that someone else is running and should clean up and bail
func (self *executorBBS) StartTask(task *models.Task, containerHandle string) error {
	originalValue := task.ToJSON()

	task.UpdatedAt = self.timeProvider.Time().UnixNano()

	task.State = models.TaskStateRunning
	task.ContainerHandle = containerHandle

	return retryIndefinitelyOnStoreTimeout(func() error {
		return self.store.CompareAndSwap(storeadapter.StoreNode{
			Key:   taskSchemaPath(task),
			Value: originalValue,
		}, storeadapter.StoreNode{
			Key:   taskSchemaPath(task),
			Value: task.ToJSON(),
		})
	})
}
开发者ID:vito,项目名称:fake-diego-release,代码行数:21,代码来源:executor_bbs.go

示例6: ClaimTask

// The executor calls this when it wants to claim a runonce
// stagerBBS will retry this repeatedly if it gets a StoreTimeout error (up to N seconds?)
// If this fails, the executor should assume that someone else is handling the claim and should bail
func (self *executorBBS) ClaimTask(task *models.Task, executorID string) error {
	originalValue := task.ToJSON()

	task.UpdatedAt = self.timeProvider.Time().UnixNano()

	task.State = models.TaskStateClaimed
	task.ExecutorID = executorID

	return retryIndefinitelyOnStoreTimeout(func() error {
		return self.store.CompareAndSwap(storeadapter.StoreNode{
			Key:   taskSchemaPath(task),
			Value: originalValue,
		}, storeadapter.StoreNode{
			Key:   taskSchemaPath(task),
			Value: task.ToJSON(),
		})
	})
}
开发者ID:vito,项目名称:fake-diego-release,代码行数:21,代码来源:executor_bbs.go

示例7: ResolvingTask

func (s *stagerBBS) ResolvingTask(task *models.Task) error {
	originalValue := task.ToJSON()

	task.UpdatedAt = s.timeProvider.Time().UnixNano()
	task.State = models.TaskStateResolving

	return retryIndefinitelyOnStoreTimeout(func() error {
		return s.store.CompareAndSwap(storeadapter.StoreNode{
			Key:   taskSchemaPath(task),
			Value: originalValue,
		}, storeadapter.StoreNode{
			Key:   taskSchemaPath(task),
			Value: task.ToJSON(),
		})
	})
}
开发者ID:vito,项目名称:fake-diego-release,代码行数:16,代码来源:stager_bbs.go

示例8: demoteToCompleted

func demoteToCompleted(task models.Task) models.Task {
	task.State = models.TaskStateCompleted
	return task
}
开发者ID:vito,项目名称:fake-diego-release,代码行数:4,代码来源:executor_bbs.go

示例9: demoteToPending

func demoteToPending(task models.Task) models.Task {
	task.State = models.TaskStatePending
	task.ExecutorID = ""
	task.ContainerHandle = ""
	return task
}
开发者ID:vito,项目名称:fake-diego-release,代码行数:6,代码来源:executor_bbs.go

示例10: markTaskFailed

func markTaskFailed(task models.Task, reason string) models.Task {
	task.State = models.TaskStateCompleted
	task.Failed = true
	task.FailureReason = reason
	return task
}
开发者ID:vito,项目名称:fake-diego-release,代码行数:6,代码来源:executor_bbs.go


注:本文中的runtime-schema/models.Task类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。