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 }
func (unit *workUnit) ClearActiveAttempt() error { repr := restdata.WorkUnit{} repr.ActiveAttemptURL = "-" return unit.Put(repr, nil) }