Is this how StartingBuildAgentsFilter is supposed to work?

I'm trying to use StartingBuildAgentsFilter to make certain agents unavailble to builds that take more than x minutes to run.  I think I have it filtering out agents the way it is supposed to, except when it filters out all available idle agents, the filter gets called every few milliseconds.  Is this the correct behavior?  I would expect it to just add the build to the queue with a reduced set of available agents instead of continually rerunning the filter.  Is my approach the best way to handle this?  I don't want to end up pegging the server cpu when it has 50 builds queued and is constantly running this filter for all of them.

In case it helps, this is a simplified version of the groovy class that is implementing StartingBuildAgentsFilter:

class ExpressLaneAgentsFilter implements StartingBuildAgentsFilter {     @NotNull     @Override     AgentsFilterResult filterAgents(@NotNull final AgentsFilterContext context) {         Collection<SBuildAgent> agentsForStartingBuild = context.agentsForStartingBuild         def expressLaneAgentNames = ["agent 1", "agent 2"]         def filteredAgents = agentsForStartingBuild.findAll{!expressLaneAgentNames.contains(it.name)}         Loggers.SERVER.debug "filteredAgents: " + filteredAgents.collect{it.name}.join(", ")         new AgentsFilterResult(filteredConnectedAgents: filteredAgents)     } }

2 comments
Comment actions Permalink

Hi Will,

Yes, StartingBuildAgentsFilter can be invoked often. It is used particularly when estimates for the builds in the queue are calculated. For a more specific answer, the call stacktraces might need to be analyzed.

Generally, you should not perform long operations inside the method. Simple implementation like the one you included should cause no problems to my understanding.

0
Comment actions Permalink

Thanks for clarifying that.  I suspected that was the case, but I just needed to be sure before I continue down that path.

0

Please sign in to leave a comment.