Пример #1
0
func (rc *RegistryClient) Unit(name string) (*schema.Unit, error) {
	rUnit, err := rc.Registry.Unit(name)
	if err != nil || rUnit == nil {
		return nil, err
	}

	var sUnit *job.ScheduledUnit
	// Only non-global units have an associated Schedule
	if !rUnit.IsGlobal() {
		sUnit, err = rc.Registry.ScheduledUnit(name)
		if err != nil {
			return nil, err
		}
	}

	return schema.MapUnitToSchemaUnit(rUnit, sUnit), nil
}
Пример #2
0
func (rc *RegistryClient) Units() ([]*schema.Unit, error) {
	rUnits, err := rc.Registry.Units()
	if err != nil {
		return nil, err
	}

	sUnits, err := rc.Registry.Schedule()
	if err != nil {
		return nil, err
	}

	sUnitMap := make(map[string]*job.ScheduledUnit, len(sUnits))
	for _, sUnit := range sUnits {
		sUnit := sUnit
		sUnitMap[sUnit.Name] = &sUnit
	}

	units := make([]*schema.Unit, len(rUnits))
	for i, ru := range rUnits {
		units[i] = schema.MapUnitToSchemaUnit(&ru, sUnitMap[ru.Name])
	}

	return units, nil
}