Skip to content

Commit

Permalink
Fix workspace lock for expired jobs (#832)
Browse files Browse the repository at this point in the history
* Fix workspace lock for expired jobs
  • Loading branch information
alfespa17 committed May 3, 2024
1 parent 398bcb5 commit a0e0cf2
Showing 1 changed file with 8 additions and 4 deletions.
Expand Up @@ -65,7 +65,7 @@ public void execute(JobExecutionContext jobExecutionContext) throws JobExecution
Date jobExpiration = DateUtils.addHours(job.getCreatedDate(), 6);
Date currentTime = new Date(System.currentTimeMillis());
log.info("Job {} should be completed before {}, current time {}", job.getId(), jobExpiration, currentTime);
if(currentTime.after(jobExpiration)){
if (currentTime.after(jobExpiration)) {
log.error("Job has been running for more than 6 hours, cancelling running job");
try {
job.setStatus(JobStatus.failed);
Expand All @@ -74,6 +74,10 @@ public void execute(JobExecutionContext jobExecutionContext) throws JobExecution
log.warn("Deleting Job Context {} from Quartz", PREFIX_JOB_CONTEXT + job.getId());
updateJobStepsWithStatus(job.getId(), JobStatus.failed);
jobExecutionContext.getScheduler().deleteJob(new JobKey(PREFIX_JOB_CONTEXT + job.getId()));
if (job.getWorkspace().isLocked()) {
log.warn("Release Workspace {} Lock for job id {}", job.getWorkspace().getId(), job.getId());
unlockWorkspace(job);
}
} catch (Exception e) {
log.error(e.getMessage());
}
Expand All @@ -87,8 +91,8 @@ public void execute(JobExecutionContext jobExecutionContext) throws JobExecution
Arrays.asList(JobStatus.failed, JobStatus.completed, JobStatus.rejected, JobStatus.cancelled, JobStatus.waitingApproval, JobStatus.approved),
job.getId()
);
if(previousJobs.isPresent() && previousJobs.get().size() > 0 ){
log.warn("Job {} is waiting for previous jobs to be completed...", jobId);
if (previousJobs.isPresent() && previousJobs.get().size() > 0) {
log.warn("Job {} is waiting for previous jobs to be completed...", jobId);
} else {

switch (job.getStatus()) {
Expand Down Expand Up @@ -153,7 +157,7 @@ private void executePendingJob(Job job, JobExecutionContext jobExecutionContext)
}
break;
case approval:
if(!job.isAutoApply()) {
if (!job.isAutoApply()) {
job.setStatus(JobStatus.waitingApproval);
job.setApprovalTeam(flow.get().getTeam());
jobRepository.save(job);
Expand Down

0 comments on commit a0e0cf2

Please sign in to comment.