コード例 #1
0
ファイル: work_spec.go プロジェクト: diffeo/go-coordinate
func (spec *workSpec) AddWorkUnit(name string, data map[string]interface{}, meta coordinate.WorkUnitMeta) (coordinate.WorkUnit, error) {
	repr := restdata.WorkUnit{}
	repr.Name = name
	repr.Data = data
	repr.Meta = &meta

	unit := workUnit{workSpec: spec}
	err := spec.PostTo(spec.Representation.WorkUnitsURL, map[string]interface{}{}, repr, &unit.Representation)
	if err == nil {
		unit.URL, err = spec.Template(unit.Representation.URL, map[string]interface{}{})
	}
	if err == nil {
		return &unit, nil
	}
	return nil, err
}
コード例 #2
0
ファイル: work_unit.go プロジェクト: diffeo/go-coordinate
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
0
ファイル: work_unit.go プロジェクト: diffeo/go-coordinate
func (unit *workUnit) SetMeta(meta coordinate.WorkUnitMeta) error {
	repr := restdata.WorkUnit{}
	repr.Meta = &meta
	return unit.Put(repr, nil)
}