예제 #1
0
// DelWorkUnits deletes work units from an existing work spec.  If
// options is empty, this does nothing.  On success, returns the
// number of work units deleted.
func (jobs *JobServer) DelWorkUnits(workSpecName string, options map[string]interface{}) (int, string, error) {
	workSpec, err := jobs.Namespace.WorkSpec(workSpecName)
	var (
		count      int
		dwuOptions DelWorkUnitsOptions
		status     coordinate.WorkUnitStatus
	)
	if err == nil {
		err = decode(&dwuOptions, options)
	}
	if err == nil && !dwuOptions.All {
		status, err = translateWorkUnitStatus(dwuOptions.State)
	}
	if err == nil {
		var query coordinate.WorkUnitQuery
		if !dwuOptions.All {
			if dwuOptions.WorkUnitKeys != nil {
				query.Names = dwuOptions.WorkUnitKeys
			} else if status != coordinate.AnyStatus {
				query.Statuses = []coordinate.WorkUnitStatus{status}
			}
		}
		count, err = workSpec.DeleteWorkUnits(query)
	}
	return count, "", err
}
예제 #2
0
// PrioritizeWorkUnits changes the priorities of some number of work
// units.  The actual work units are in options["work_unit_keys"].  A
// higher priority results in the work units being scheduled sooner.
func (jobs *JobServer) PrioritizeWorkUnits(workSpecName string, options map[string]interface{}) (bool, string, error) {
	var (
		err      error
		query    coordinate.WorkUnitQuery
		workSpec coordinate.WorkSpec
	)
	pwuOptions := PrioritizeWorkUnitsOptions{
		Priority:   math.NaN(),
		Adjustment: math.NaN(),
	}
	workSpec, err = jobs.Namespace.WorkSpec(workSpecName)
	if err == nil {
		err = decode(&pwuOptions, options)
	}
	if err == nil && pwuOptions.WorkUnitKeys == nil {
		return false, "missing work_unit_keys", err
	}
	if err == nil {
		query.Names = pwuOptions.WorkUnitKeys
		if !math.IsNaN(pwuOptions.Priority) {
			err = workSpec.SetWorkUnitPriorities(query, pwuOptions.Priority)
		} else if !math.IsNaN(pwuOptions.Adjustment) {
			err = workSpec.AdjustWorkUnitPriorities(query, pwuOptions.Adjustment)
		}
	}
	return err == nil, "", err
}