Compare commits

..

2 Commits

Author SHA1 Message Date
vithobaa 7e82bd6a98 grrg 2026-06-30 11:57:07 +05:30
vithobaa 172fae7f40 fix: instantly create execution from scheduler instead of waiting for agent poll 2026-06-30 11:56:25 +05:30
4 changed files with 47 additions and 6 deletions

View File

@ -211,11 +211,12 @@ public class AgentService {
.filter(s -> agentOrgId == null || agentOrgId.equals(s.getOrgId())) .filter(s -> agentOrgId == null || agentOrgId.equals(s.getOrgId()))
.toList(); .toList();
if (activeJobs.isEmpty()) { if (!activeJobs.isEmpty()) {
return ResponseEntity.noContent().build(); unwrapSchedulerToJobs(activeJobs.get(0), agentOrgId);
} }
Scheduler job = activeJobs.get(0); @Transactional
public void unwrapSchedulerToJobs(Scheduler job, Long agentOrgId) {
job.setStatus("processing"); job.setStatus("processing");
schedulerRepository.save(job); schedulerRepository.save(job);
@ -297,6 +298,7 @@ public class AgentService {
} }
} }
} }
}
// Bug fix: replaced unbounded recursion with a simple retry pick up one of the jobs just created. // 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 // The recursive approach had no depth limit and could cause a StackOverflowError

View File

@ -19,9 +19,11 @@ public class CronExecutionEngine {
private static final Logger logger = LoggerFactory.getLogger(CronExecutionEngine.class); private static final Logger logger = LoggerFactory.getLogger(CronExecutionEngine.class);
private final SchedulerRepository schedulerRepository; private final SchedulerRepository schedulerRepository;
private final AgentService agentService;
public CronExecutionEngine(SchedulerRepository schedulerRepository) { public CronExecutionEngine(SchedulerRepository schedulerRepository, AgentService agentService) {
this.schedulerRepository = schedulerRepository; this.schedulerRepository = schedulerRepository;
this.agentService = agentService;
} }
// Runs at the 0th second of every minute // Runs at the 0th second of every minute
@ -80,6 +82,7 @@ public class CronExecutionEngine {
// Check time match (truncated to minutes) // Check time match (truncated to minutes)
LocalTime nowTime = now.toLocalTime().truncatedTo(ChronoUnit.MINUTES); LocalTime nowTime = now.toLocalTime().truncatedTo(ChronoUnit.MINUTES);
LocalTime targetTime = scheduledTime.truncatedTo(ChronoUnit.MINUTES); LocalTime targetTime = scheduledTime.truncatedTo(ChronoUnit.MINUTES);
logger.info("Evaluating schedule ID {} | Timezone: {} | nowTime: {} | targetTime: {}", s.getId(), s.getTimezone(), nowTime, targetTime);
if (!nowTime.equals(targetTime)) { if (!nowTime.equals(targetTime)) {
return false; return false;
} }
@ -199,7 +202,12 @@ public class CronExecutionEngine {
job.setStatus("active"); job.setStatus("active");
job.setOrgId(original.getOrgId()); job.setOrgId(original.getOrgId());
job.setEnvironmentId(original.getEnvironmentId()); job.setEnvironmentId(original.getEnvironmentId());
schedulerRepository.save(job); job = schedulerRepository.save(job);
logger.info("Queued test suite '{}' for execution via local agent polling", job.getTestSuiteName()); logger.info("Queued test suite '{}' for execution. Instantly unwrapping to executions.", job.getTestSuiteName());
try {
agentService.unwrapSchedulerToJobs(job, original.getOrgId());
} catch(Exception e) {
logger.error("Failed to unwrap scheduler into execution: " + e.getMessage(), e);
}
} }
} }

12
test_kolkata.java Normal file
View File

@ -0,0 +1,12 @@
import java.time.*;
public class test_kolkata {
public static void main(String[] args) {
try {
System.out.println(ZoneId.of("Asia/Kolkata"));
} catch(Exception e) {
e.printStackTrace();
}
}
}

19
test_tz.java Normal file
View File

@ -0,0 +1,19 @@
import java.time.*;
import java.time.temporal.ChronoUnit;
public class test_tz {
public static void main(String[] args) {
try {
ZoneId zone = ZoneId.of("Asia/Calcutta");
LocalDateTime now = LocalDateTime.now(zone).truncatedTo(ChronoUnit.MINUTES);
System.out.println("Now in Asia/Calcutta: " + now);
LocalTime scheduledTime = LocalTime.parse("11:48:00");
LocalTime nowTime = now.toLocalTime();
System.out.println("Is equal? " + nowTime.equals(scheduledTime));
} catch(Exception e) {
e.printStackTrace();
}
}
}