fix: resolve AgentService compilation error
This commit is contained in:
parent
7e82bd6a98
commit
e263332d65
|
|
@ -215,6 +215,37 @@ public class AgentService {
|
|||
unwrapSchedulerToJobs(activeJobs.get(0), agentOrgId);
|
||||
}
|
||||
|
||||
// Pick up one of the newly created jobs
|
||||
List<com.autopilot.localagent_cloud.model.Job> retryJobs = jobRepository.findNextAvailableJobs(
|
||||
agentId, groupIDsForQuery, PageRequest.of(0, 50));
|
||||
com.autopilot.localagent_cloud.model.Job retryJob = retryJobs.stream().filter(j -> {
|
||||
if (j.getBrowserVersion() == null || j.getBrowserVersion().isBlank()) return true;
|
||||
if (finalAgentBrowserVer.isBlank()) return false;
|
||||
String reqMajor = j.getBrowserVersion().split("\\.")[0];
|
||||
String agentMajor = finalAgentBrowserVer.split("\\.")[0];
|
||||
return reqMajor.equals(agentMajor);
|
||||
}).findFirst().orElse(null);
|
||||
|
||||
if (retryJob != null) {
|
||||
retryJob.setStatus("ASSIGNED");
|
||||
retryJob.setAgentId(agentId);
|
||||
retryJob.setLeaseExpiresAt(java.time.LocalDateTime.now().plusMinutes(10));
|
||||
jobRepository.save(retryJob);
|
||||
try {
|
||||
Map<String, Object> runRequest = objectMapper.readValue(retryJob.getPayloadJson(), Map.class);
|
||||
runRequest.put("jobId", retryJob.getId());
|
||||
Map<String, Object> jobDto = new HashMap<>();
|
||||
jobDto.put("executionId", retryJob.getExecutionId());
|
||||
jobDto.put("jobId", retryJob.getId());
|
||||
jobDto.put("payloadJson", objectMapper.writeValueAsString(runRequest));
|
||||
return ResponseEntity.ok(jobDto);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.internalServerError().build();
|
||||
}
|
||||
}
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void unwrapSchedulerToJobs(Scheduler job, Long agentOrgId) {
|
||||
job.setStatus("processing");
|
||||
|
|
@ -300,39 +331,6 @@ public class AgentService {
|
|||
}
|
||||
}
|
||||
|
||||
// Bug fix: replaced unbounded recursion with a simple retry — pick up one of the jobs just created.
|
||||
// The recursive approach had no depth limit and could cause a StackOverflowError
|
||||
// if job creation failed unexpectedly.
|
||||
List<com.autopilot.localagent_cloud.model.Job> retryJobs = jobRepository.findNextAvailableJobs(
|
||||
agentId, groupIDsForQuery, PageRequest.of(0, 50));
|
||||
com.autopilot.localagent_cloud.model.Job retryJob = retryJobs.stream().filter(j -> {
|
||||
if (j.getBrowserVersion() == null || j.getBrowserVersion().isBlank()) return true;
|
||||
if (finalAgentBrowserVer.isBlank()) return false;
|
||||
String reqMajor = j.getBrowserVersion().split("\\.")[0];
|
||||
String agentMajor = finalAgentBrowserVer.split("\\.")[0];
|
||||
return reqMajor.equals(agentMajor);
|
||||
}).findFirst().orElse(null);
|
||||
|
||||
if (retryJob != null) {
|
||||
retryJob.setStatus("ASSIGNED");
|
||||
retryJob.setAgentId(agentId);
|
||||
retryJob.setLeaseExpiresAt(java.time.LocalDateTime.now().plusMinutes(10));
|
||||
jobRepository.save(retryJob);
|
||||
try {
|
||||
Map<String, Object> runRequest = objectMapper.readValue(retryJob.getPayloadJson(), Map.class);
|
||||
runRequest.put("jobId", retryJob.getId());
|
||||
Map<String, Object> jobDto = new HashMap<>();
|
||||
jobDto.put("executionId", retryJob.getExecutionId());
|
||||
jobDto.put("jobId", retryJob.getId());
|
||||
jobDto.put("payloadJson", objectMapper.writeValueAsString(runRequest));
|
||||
return ResponseEntity.ok(jobDto);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.internalServerError().build();
|
||||
}
|
||||
}
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@SuppressWarnings("unchecked")
|
||||
public ResponseEntity<Void> postResults(Long executionId, Map<String, Object> result) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue