本文整理汇总了Golang中github.com/diffeo/go-coordinate/coordinate.WorkUnit.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang WorkUnit.Name方法的具体用法?Golang WorkUnit.Name怎么用?Golang WorkUnit.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/diffeo/go-coordinate/coordinate.WorkUnit
的用法示例。
在下文中一共展示了WorkUnit.Name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WorkUnitsPost
func (api *restAPI) WorkUnitsPost(ctx *context, in interface{}) (interface{}, error) {
var (
err error
unit coordinate.WorkUnit
short restdata.WorkUnitShort
)
repr, valid := in.(restdata.WorkUnit)
if !valid {
err = errUnmarshal
}
if err == nil {
var meta coordinate.WorkUnitMeta
if repr.Meta != nil {
meta = *repr.Meta
}
unit, err = ctx.WorkSpec.AddWorkUnit(repr.Name, repr.Data, meta)
}
if err == nil {
err = api.fillWorkUnitShort(ctx.Namespace, ctx.WorkSpec, unit.Name(), &short)
}
if err == nil {
resp := responseCreated{
Location: short.URL,
Body: short,
}
return resp, nil
}
return nil, err
}
示例2: fillWorkUnit
func (api *restAPI) fillWorkUnit(namespace coordinate.Namespace, spec coordinate.WorkSpec, unit coordinate.WorkUnit, repr *restdata.WorkUnit) error {
err := api.fillWorkUnitShort(namespace, spec, unit.Name(), &repr.WorkUnitShort)
if err == nil {
repr.Data, err = unit.Data()
}
if err == nil {
var meta coordinate.WorkUnitMeta
meta, err = unit.Meta()
repr.Meta = &meta
}
if err == nil {
repr.Status, err = unit.Status()
}
if err == nil {
err = buildURLs(api.Router,
"namespace", namespace.Name(),
"spec", spec.Name(),
"unit", unit.Name(),
).
URL(&repr.WorkSpecURL, "workSpec").
URL(&repr.AttemptsURL, "workUnitAttempts").
Error
}
if err == nil {
var attempt coordinate.Attempt
attempt, err = unit.ActiveAttempt()
if err == nil && attempt != nil {
// This is cheating, a little, but it's probably
// the easiest way to reuse this code
var short restdata.AttemptShort
err = api.fillAttemptShort(namespace, attempt, &short)
if err == nil {
repr.ActiveAttemptURL = short.URL
}
}
}
return err
}
示例3: MakeAttempt
func (w *worker) MakeAttempt(unit coordinate.WorkUnit, lifetime time.Duration) (coordinate.Attempt, error) {
req := restdata.AttemptSpecific{
WorkSpec: unit.WorkSpec().Name(),
WorkUnit: unit.Name(),
Lifetime: lifetime,
}
var a attempt
err := w.PostTo(w.Representation.MakeAttemptURL, map[string]interface{}{}, req, &a.Representation)
if err != nil {
return nil, err
}
a.URL, err = w.URL.Parse(a.Representation.URL)
if err != nil {
return nil, err
}
aUnit, _ := unit.(*workUnit)
err = a.fillReferences(aUnit, w)
if err != nil {
return nil, err
}
return &a, nil
}
示例4: UpdateWorkUnit
// UpdateWorkUnit causes some state change in a work unit. If the
// work unit is pending, this is the principal interface to complete
// or renew it; if it is already complete this can cause it to be
// retried.
func (jobs *JobServer) UpdateWorkUnit(
workSpecName string,
workUnitKey string,
options map[string]interface{},
) (bool, string, error) {
// Note that in several corner cases, the behavior of this as
// written disagrees with Python coordinated's:
//
// * If neither "lease_time" nor "status" is specified,
// Python coordinated immediately returns False without
// checking if workUnitKey is valid
//
// * Python coordinated allows arbitrary status changes,
// including AVAILABLE -> FINISHED
//
// * This openly ignores "worker_id", as distinct from Python
// coordinated, which logs an obscure warning and changes it,
// but only on a renew
var (
attempt coordinate.Attempt
changed bool
err error
status coordinate.AttemptStatus
uwuOptions UpdateWorkUnitOptions
workSpec coordinate.WorkSpec
workUnit coordinate.WorkUnit
)
err = decode(&uwuOptions, options)
if err == nil {
workSpec, err = jobs.Namespace.WorkSpec(workSpecName)
}
if err == nil {
workUnit, err = workSpec.WorkUnit(workUnitKey)
}
if err == nil {
if workUnit == nil {
return false, fmt.Sprintf("no such work unit key=%v", workUnitKey), nil
}
}
if err == nil {
attempt, err = workUnit.ActiveAttempt()
}
if err == nil && attempt != nil {
status, err = attempt.Status()
}
if err == nil && attempt != nil {
if status == coordinate.Expired || status == coordinate.Retryable {
// The Python Coordinate API sees both of these
// statuses as "available", and we want to fall
// into the next block.
attempt = nil
}
}
if err == nil && attempt == nil {
// Caller is trying to manipulate an AVAILABLE work
// unit. Either they are trying to change the work
// unit data in place, or they are trying to jump a
// work unit directly to a completed state. (The
// latter is possible during the Python work unit
// parent cleanup, if the timing is bad.)
if uwuOptions.Status == Available || uwuOptions.Status == 0 {
// The only thing we are doing is changing the
// work unit data.
if uwuOptions.Data != nil {
meta, err := workUnit.Meta()
if err == nil {
_, err = workSpec.AddWorkUnit(workUnit.Name(), uwuOptions.Data, meta)
}
if err == nil {
changed = true
}
}
return changed && err == nil, "", err
}
// Otherwise we are trying to transition to another
// state; so force-create an attempt.
worker, err := jobs.Namespace.Worker(uwuOptions.WorkerID)
if err == nil {
attempt, err = worker.MakeAttempt(workUnit, uwuOptions.LeaseDuration())
status = coordinate.Pending
}
}
if err == nil {
switch status {
case coordinate.Pending:
changed = true // or there's an error
switch uwuOptions.Status {
case 0, Pending:
err = attempt.Renew(uwuOptions.LeaseDuration(), uwuOptions.Data)
case Available:
err = attempt.Expire(uwuOptions.Data)
case Finished:
err = attempt.Finish(uwuOptions.Data)
case Failed:
err = attempt.Fail(uwuOptions.Data)
default:
//.........这里部分代码省略.........