本文整理汇总了Golang中github.com/dmaze/goordinate/coordinate.Worker.MakeAttempt方法的典型用法代码示例。如果您正苦于以下问题:Golang Worker.MakeAttempt方法的具体用法?Golang Worker.MakeAttempt怎么用?Golang Worker.MakeAttempt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/dmaze/goordinate/coordinate.Worker
的用法示例。
在下文中一共展示了Worker.MakeAttempt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: makeWorkUnits
// makeWorkUnits creates a handful of work units within a work spec.
// These have keys "available", "pending", "finished", "failed",
// "expired", and "retryable", and wind up in the corresponding
// states.
func makeWorkUnits(spec coordinate.WorkSpec, worker coordinate.Worker) (map[string]coordinate.WorkUnit, error) {
result := map[string]coordinate.WorkUnit{
"available": nil,
"pending": nil,
"finished": nil,
"failed": nil,
"expired": nil,
"retryable": nil,
}
for key := range result {
unit, err := spec.AddWorkUnit(key, map[string]interface{}{}, 0)
if err != nil {
return nil, err
}
result[key] = unit
// Run the workflow
if key == "available" {
continue
}
attempt, err := worker.MakeAttempt(unit, time.Duration(0))
if err != nil {
return nil, err
}
switch key {
case "pending":
{
} // leave it running
case "finished":
err = attempt.Finish(nil)
case "failed":
err = attempt.Fail(nil)
case "expired":
err = attempt.Expire(nil)
case "retryable":
err = attempt.Retry(nil)
}
if err != nil {
return nil, err
}
}
return result, nil
}