Skip to content

Commit 867863d

Browse files
ivicacclaude
andcommitted
4756 Fix deleting project deployment with subflow jobs
Recursively delete child subflow jobs before the parent's task_executions to satisfy the fk_job_task_execution constraint. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 56adb2a commit 867863d

8 files changed

Lines changed: 49 additions & 0 deletions

File tree

  • server
    • ee/libs/atlas/atlas-execution/atlas-execution-remote-client/src/main/java/com/bytechef/ee/atlas/execution/remote/client/service
    • libs

server/ee/libs/atlas/atlas-execution/atlas-execution-remote-client/src/main/java/com/bytechef/ee/atlas/execution/remote/client/service/RemoteJobServiceClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public Optional<Job> fetchLastWorkflowJob(List<String> workflowIds) {
7676
throw new UnsupportedOperationException();
7777
}
7878

79+
@Override
80+
public List<Long> getChildJobIds(long parentJobId) {
81+
throw new UnsupportedOperationException();
82+
}
83+
7984
@Override
8085
public List<Job> getJobs(List<Long> ids) {
8186
throw new UnsupportedOperationException();

server/libs/atlas/atlas-execution/atlas-execution-api/src/main/java/com/bytechef/atlas/execution/service/JobService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public interface JobService {
4040

4141
Optional<Job> fetchLastWorkflowJob(List<String> workflowIds);
4242

43+
List<Long> getChildJobIds(long parentJobId);
44+
4345
Job getJob(long id);
4446

4547
List<Job> getJobs(List<Long> ids);

server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-api/src/main/java/com/bytechef/atlas/execution/repository/JobRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public interface JobRepository {
4646

4747
List<Job> findAllByIdIn(List<Long> ids);
4848

49+
List<Long> findAllIdsByParentJobId(Long parentJobId);
50+
4951
List<Job> findAllByWorkflowId(String workflowId);
5052

5153
Optional<Job> findById(Long id);

server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-jdbc/src/main/java/com/bytechef/atlas/execution/repository/jdbc/JdbcJobRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,10 @@ public interface JdbcJobRepository
6565
@Query("SELECT * FROM job j WHERE j.id = (SELECT job_id FROM task_execution te WHERE te.id=:taskExecutionId)")
6666
Optional<Job> findByTaskExecutionId(@Param("taskExecutionId") Long taskExecutionId);
6767

68+
@Override
69+
@Query("SELECT j.id FROM job j WHERE j.parent_task_execution_id IN "
70+
+ "(SELECT te.id FROM task_execution te WHERE te.job_id=:parentJobId)")
71+
List<Long> findAllIdsByParentJobId(@Param("parentJobId") Long parentJobId);
72+
6873
Job save(Job job);
6974
}

server/libs/atlas/atlas-execution/atlas-execution-repository/atlas-execution-repository-memory/src/main/java/com/bytechef/atlas/execution/repository/memory/InMemoryJobRepository.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ public List<Job> findAllByWorkflowId(String workflowId) {
9090
throw new UnsupportedOperationException();
9191
}
9292

93+
@Override
94+
public List<Long> findAllIdsByParentJobId(Long parentJobId) {
95+
List<Long> parentTaskExecutionIds = inMemoryTaskExecutionRepository.findAllByJobIdOrderByIdDesc(parentJobId)
96+
.stream()
97+
.map(TaskExecution::getId)
98+
.filter(Objects::nonNull)
99+
.toList();
100+
101+
return cache.values()
102+
.stream()
103+
.filter(job -> {
104+
Long parentTaskExecutionId = job.getParentTaskExecutionId();
105+
106+
return parentTaskExecutionId != null && parentTaskExecutionIds.contains(parentTaskExecutionId);
107+
})
108+
.map(Job::getId)
109+
.filter(Objects::nonNull)
110+
.toList();
111+
}
112+
93113
@Override
94114
public Optional<Job> findById(Long id) {
95115
return Optional.ofNullable(cache.get(TenantCacheKeyUtils.getKey(id)));

server/libs/atlas/atlas-execution/atlas-execution-service/src/main/java/com/bytechef/atlas/execution/facade/JobFacadeImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public long createJob(JobParametersDTO jobParametersDTO) {
9898
@Override
9999
@Transactional
100100
public void deleteJob(long id) {
101+
for (long childJobId : jobService.getChildJobIds(id)) {
102+
deleteJob(childJobId);
103+
}
104+
101105
taskExecutionService.deleteJobTaskExecutions(id);
102106

103107
jobService.deleteJob(id);

server/libs/atlas/atlas-execution/atlas-execution-service/src/main/java/com/bytechef/atlas/execution/service/JobServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ public Optional<Job> fetchLastWorkflowJob(List<String> workflowIds) {
9090
return jobRepository.findTop1ByWorkflowIdInOrderByIdDesc(workflowIds);
9191
}
9292

93+
@Override
94+
@Transactional(readOnly = true)
95+
public List<Long> getChildJobIds(long parentJobId) {
96+
return jobRepository.findAllIdsByParentJobId(parentJobId);
97+
}
98+
9399
@Override
94100
@Transactional(readOnly = true)
95101
public Job getJob(long id) {

server/libs/platform/platform-job-sync/src/main/java/com/bytechef/platform/job/sync/executor/JobServiceWrapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626

2727
public record JobServiceWrapper(JobSyncExecutor.JobFactoryFunction jobFactoryFunction) implements JobService {
2828

29+
@Override
30+
public List<Long> getChildJobIds(long parentJobId) {
31+
throw new UnsupportedOperationException();
32+
}
33+
2934
@Override
3035
public Job getJob(long id) {
3136
throw new UnsupportedOperationException();

0 commit comments

Comments
 (0)