// FindTasks finds Tasks which match the given Criteria
FindTasks finds Tasks which match the given Criteria
// FindTasks finds Tasks which match the given Criteria
func FindTasks(profile *config.Profile, criteria Criteria) (Messages, error) {
	caller := helper.NewCaller(profile)
	filters := []Filter{TaskIDFilter(criteria.TaskID, criteria.Fuzzy)}
	if len(criteria.TaskStates) > 0 {
		filters = append(filters, TaskStateFilter(criteria.TaskStates))
	}
	switch {
	case criteria.TaskName != "":
		msgs, err := FromMaster(caller.CallMaster(master.GetTasks()))
		if err != nil {
			return nil, err
		}
		filters = append(filters, TaskNameFilter(criteria.TaskName, criteria.Fuzzy))
		return msgs.FindMany(filters...), nil
	case criteria.TaskID != "":
		msgs, err := FromMaster(caller.CallMaster(master.GetTasks()))
		if err != nil {
			return nil, err
		}
		return msgs.FindMany(filters...), nil
	case criteria.AgentID != "":
		msgs, err := FindAgents(profile, Criteria{AgentID: criteria.AgentID})
		if err != nil {
			return nil, err
		}
		agnt, err := AsAgent(msgs.FindOne())
		if err != nil {
			return nil, err
		}
		msgs, err = FromAgent(helper.NewAgentCaller(profile, agnt).CallAgent(agent.GetTasks()))
		if err != nil {
			return nil, err
		}
		return msgs.FindMany(filters...), nil
	default:
		msgs, err := FromMaster(caller.CallMaster(master.GetTasks()))
		if err != nil {
			return nil, err
		}
		return msgs.FindMany(filters...), nil
	}
}
func FindTasks ( profile * config . Profile , criteria Criteria ) ( Messages , error ) { caller := helper . NewCaller ( profile ) filters := [ ] Filter { TaskIDFilter ( criteria . TaskID , criteria . Fuzzy ) } if len ( criteria . TaskStates ) > 0 { filters = append ( filters , TaskStateFilter ( criteria . TaskStates ) ) } switch { case criteria . TaskName != " " : msgs , err := FromMaster ( caller . CallMaster ( master . GetTasks ( ) ) ) if err != nil { return nil , err } filters = append ( filters , TaskNameFilter ( criteria . TaskName , criteria . Fuzzy ) ) return msgs . FindMany ( filters ... ) , nil case criteria . TaskID != " " : msgs , err := FromMaster ( caller . CallMaster ( master . GetTasks ( ) ) ) if err != nil { return nil , err } return msgs . FindMany ( filters ... ) , nil case criteria . AgentID != " " : msgs , err := FindAgents ( profile , Criteria { AgentID : criteria . AgentID } ) if err != nil { return nil , err } agnt , err := AsAgent ( msgs . FindOne ( ) ) if err != nil { return nil , err } msgs , err = FromAgent ( helper . NewAgentCaller ( profile , agnt ) . CallAgent ( agent . GetTasks ( ) ) ) if err != nil { return nil , err } return msgs . FindMany ( filters ... ) , nil default : msgs , err := FromMaster ( caller . CallMaster ( master . GetTasks ( ) ) ) if err != nil { return nil , err } return msgs . FindMany ( filters ... ) , nil } }
FindTasks finds Tasks which match the given Criteria
FindTasks finds Tasks which match the given Criteria
// Caller is seaching by TaskName // Caller is explicitly searching for a task or tasks that match a string // Caller wants to return all tasks on a particular agent // Search for agents with the matching ID // Only one agent may match // Build a new Caller for the resolved agent // Return all the tasks still matching any state filters