private void matchingJobForRegisteredAgents() {
Map<String, Agent> agents = agentRemoteHandler.connectedAgents();
if (agents.isEmpty()) {
return;
}
Long start = System.currentTimeMillis();
for (Map.Entry<String, Agent> entry : agents.entrySet()) {
String agentUUId = entry.getKey();
Agent agent = entry.getValue();
AgentInstance agentInstance = agentService.findAgentAndRefreshStatus(agentUUId);
if (!agentInstance.isRegistered()) {
agent.send(new Message(Action.reregister));
continue;
}
if (agentInstance.isDisabled() || !agentInstance.isIdle()) {
LOGGER.debug("Ignore agent [{}] that is {} and {}", agentInstance.getAgentIdentifier(), agentInstance.getRuntimeStatus(), agentInstance.getAgentConfigStatus());
continue;
}
Work work = assignWorkToAgent(agentInstance);
if (work != NO_WORK) {
if (agentInstance.getSupportsBuildCommandProtocol()) {
BuildSettings buildSettings = createBuildSettings(((BuildWork) work).getAssignment());
agent.send(new Message(Action.build, MessageEncoding.encodeData(buildSettings)));
} else {
agent.send(new Message(Action.assignWork, MessageEncoding.encodeWork(work)));
}
}
}
LOGGER.debug("Matching {} agents with {} jobs took: {}ms", agents.size(), jobPlans.size(), System.currentTimeMillis() - start);
}