diff --git a/server/ee/libs/atlas/atlas-execution/atlas-execution-remote-client/src/main/java/com/bytechef/ee/atlas/execution/remote/client/service/RemoteJobServiceClient.java b/server/ee/libs/atlas/atlas-execution/atlas-execution-remote-client/src/main/java/com/bytechef/ee/atlas/execution/remote/client/service/RemoteJobServiceClient.java index 848463e1c67..f92860c66ba 100644 --- a/server/ee/libs/atlas/atlas-execution/atlas-execution-remote-client/src/main/java/com/bytechef/ee/atlas/execution/remote/client/service/RemoteJobServiceClient.java +++ b/server/ee/libs/atlas/atlas-execution/atlas-execution-remote-client/src/main/java/com/bytechef/ee/atlas/execution/remote/client/service/RemoteJobServiceClient.java @@ -76,6 +76,11 @@ public Optional fetchLastWorkflowJob(List workflowIds) { throw new UnsupportedOperationException(); } + @Override + public List getChildJobIds(long parentJobId) { + throw new UnsupportedOperationException(); + } + @Override public List getJobs(List ids) { throw new UnsupportedOperationException(); diff --git a/server/libs/atlas/atlas-execution/atlas-execution-api/src/main/java/com/bytechef/atlas/execution/service/JobService.java b/server/libs/atlas/atlas-execution/atlas-execution-api/src/main/java/com/bytechef/atlas/execution/service/JobService.java index ee484332eb4..380fa24bcf1 100644 --- a/server/libs/atlas/atlas-execution/atlas-execution-api/src/main/java/com/bytechef/atlas/execution/service/JobService.java +++ b/server/libs/atlas/atlas-execution/atlas-execution-api/src/main/java/com/bytechef/atlas/execution/service/JobService.java @@ -40,6 +40,8 @@ public interface JobService { Optional fetchLastWorkflowJob(List workflowIds); + List getChildJobIds(long parentJobId); + Job getJob(long id); List getJobs(List ids); diff --git a/server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-api/src/main/java/com/bytechef/atlas/execution/repository/JobRepository.java b/server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-api/src/main/java/com/bytechef/atlas/execution/repository/JobRepository.java index 140d7dd9336..29d1e72aa44 100644 --- a/server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-api/src/main/java/com/bytechef/atlas/execution/repository/JobRepository.java +++ b/server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-api/src/main/java/com/bytechef/atlas/execution/repository/JobRepository.java @@ -46,6 +46,8 @@ public interface JobRepository { List findAllByIdIn(List ids); + List findAllIdsByParentJobId(Long parentJobId); + List findAllByWorkflowId(String workflowId); Optional findById(Long id); diff --git a/server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-jdbc/src/main/java/com/bytechef/atlas/execution/repository/jdbc/JdbcJobRepository.java b/server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-jdbc/src/main/java/com/bytechef/atlas/execution/repository/jdbc/JdbcJobRepository.java index 6268de552e6..f30c335f98d 100644 --- a/server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-jdbc/src/main/java/com/bytechef/atlas/execution/repository/jdbc/JdbcJobRepository.java +++ b/server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-jdbc/src/main/java/com/bytechef/atlas/execution/repository/jdbc/JdbcJobRepository.java @@ -65,5 +65,10 @@ public interface JdbcJobRepository @Query("SELECT * FROM job j WHERE j.id = (SELECT job_id FROM task_execution te WHERE te.id=:taskExecutionId)") Optional findByTaskExecutionId(@Param("taskExecutionId") Long taskExecutionId); + @Override + @Query("SELECT j.id FROM job j WHERE j.parent_task_execution_id IN " + + "(SELECT te.id FROM task_execution te WHERE te.job_id=:parentJobId)") + List findAllIdsByParentJobId(@Param("parentJobId") Long parentJobId); + Job save(Job job); } diff --git a/server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-memory/src/main/java/com/bytechef/atlas/execution/repository/memory/InMemoryJobRepository.java b/server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-memory/src/main/java/com/bytechef/atlas/execution/repository/memory/InMemoryJobRepository.java index c157b5365f2..77bdeb2586d 100644 --- a/server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-memory/src/main/java/com/bytechef/atlas/execution/repository/memory/InMemoryJobRepository.java +++ b/server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-memory/src/main/java/com/bytechef/atlas/execution/repository/memory/InMemoryJobRepository.java @@ -90,6 +90,26 @@ public List findAllByWorkflowId(String workflowId) { throw new UnsupportedOperationException(); } + @Override + public List findAllIdsByParentJobId(Long parentJobId) { + List parentTaskExecutionIds = inMemoryTaskExecutionRepository.findAllByJobIdOrderByIdDesc(parentJobId) + .stream() + .map(TaskExecution::getId) + .filter(Objects::nonNull) + .toList(); + + return cache.values() + .stream() + .filter(job -> { + Long parentTaskExecutionId = job.getParentTaskExecutionId(); + + return parentTaskExecutionId != null && parentTaskExecutionIds.contains(parentTaskExecutionId); + }) + .map(Job::getId) + .filter(Objects::nonNull) + .toList(); + } + @Override public Optional findById(Long id) { return Optional.ofNullable(cache.get(TenantCacheKeyUtils.getKey(id))); diff --git a/server/libs/atlas/atlas-execution/atlas-execution-service/src/main/java/com/bytechef/atlas/execution/facade/JobFacadeImpl.java b/server/libs/atlas/atlas-execution/atlas-execution-service/src/main/java/com/bytechef/atlas/execution/facade/JobFacadeImpl.java index d497fb7b093..0c701bc3ee2 100644 --- a/server/libs/atlas/atlas-execution/atlas-execution-service/src/main/java/com/bytechef/atlas/execution/facade/JobFacadeImpl.java +++ b/server/libs/atlas/atlas-execution/atlas-execution-service/src/main/java/com/bytechef/atlas/execution/facade/JobFacadeImpl.java @@ -98,6 +98,10 @@ public long createJob(JobParametersDTO jobParametersDTO) { @Override @Transactional public void deleteJob(long id) { + for (long childJobId : jobService.getChildJobIds(id)) { + deleteJob(childJobId); + } + taskExecutionService.deleteJobTaskExecutions(id); jobService.deleteJob(id); diff --git a/server/libs/atlas/atlas-execution/atlas-execution-service/src/main/java/com/bytechef/atlas/execution/service/JobServiceImpl.java b/server/libs/atlas/atlas-execution/atlas-execution-service/src/main/java/com/bytechef/atlas/execution/service/JobServiceImpl.java index d6f978121dc..d7e31d4ad39 100644 --- a/server/libs/atlas/atlas-execution/atlas-execution-service/src/main/java/com/bytechef/atlas/execution/service/JobServiceImpl.java +++ b/server/libs/atlas/atlas-execution/atlas-execution-service/src/main/java/com/bytechef/atlas/execution/service/JobServiceImpl.java @@ -90,6 +90,12 @@ public Optional fetchLastWorkflowJob(List workflowIds) { return jobRepository.findTop1ByWorkflowIdInOrderByIdDesc(workflowIds); } + @Override + @Transactional(readOnly = true) + public List getChildJobIds(long parentJobId) { + return jobRepository.findAllIdsByParentJobId(parentJobId); + } + @Override @Transactional(readOnly = true) public Job getJob(long id) { diff --git a/server/libs/platform/platform-job-sync/src/main/java/com/bytechef/platform/job/sync/executor/JobServiceWrapper.java b/server/libs/platform/platform-job-sync/src/main/java/com/bytechef/platform/job/sync/executor/JobServiceWrapper.java index 999c3741461..5115592f6fe 100644 --- a/server/libs/platform/platform-job-sync/src/main/java/com/bytechef/platform/job/sync/executor/JobServiceWrapper.java +++ b/server/libs/platform/platform-job-sync/src/main/java/com/bytechef/platform/job/sync/executor/JobServiceWrapper.java @@ -26,6 +26,11 @@ public record JobServiceWrapper(JobSyncExecutor.JobFactoryFunction jobFactoryFunction) implements JobService { + @Override + public List getChildJobIds(long parentJobId) { + throw new UnsupportedOperationException(); + } + @Override public Job getJob(long id) { throw new UnsupportedOperationException();