Skip to content

Commit

Permalink
Added SQL migration. Removed isAllowedExecutionOverlap, as the Disall…
Browse files Browse the repository at this point in the history
…owConcurrentExecution annotation can be applied to the job.
  • Loading branch information
mattwilshire committed Oct 2, 2024
1 parent 893f4af commit fb4e02b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
11 changes: 0 additions & 11 deletions webapp/src/main/java/com/box/l10n/mojito/entity/ScheduledJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ public class ScheduledJob extends BaseEntity {
@Column(name = "end_date")
private Date endDate;

@Column(name = "allow_execution_overlap")
private boolean allowExecutionOverlap;

@PostLoad
public void deserializeProperties() {
ObjectMapper objectMapper = new ObjectMapper();
Expand Down Expand Up @@ -153,12 +150,4 @@ public Date getEndDate() {
public void setEndDate(Date endDate) {
this.endDate = endDate;
}

public boolean isAllowExecutionOverlap() {
return allowExecutionOverlap;
}

public void setAllowExecutionOverlap(boolean allowExecutionOverlap) {
this.allowExecutionOverlap = allowExecutionOverlap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ public void pushJobToDB(ThirdPartySyncJobConfig jobConfig) {

scheduledJob.setProperties(thirdPartySyncProperties);

scheduledJob.setAllowExecutionOverlap(false);

try {
scheduledJobRepository.save(scheduledJob);
} catch (DataIntegrityViolationException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.box.l10n.mojito.service.scheduledjob;

import com.box.l10n.mojito.entity.ScheduledJob;
import org.quartz.JobExecutionContext;
import org.quartz.Trigger;
import org.quartz.listeners.TriggerListenerSupport;
import org.slf4j.Logger;
Expand All @@ -22,15 +21,6 @@ public String getName() {
return "ScheduledJobTriggerListener";
}

@Override
public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
// Returning true vetoes the job execution, if its in progress & we don't allow overlapping
// then skip execution
ScheduledJob job = scheduledJobRepository.findByJobKey(context.getJobDetail().getKey());
return job.getJobStatus().equals(ScheduledJobStatus.IN_PROGRESS)
&& !job.isAllowExecutionOverlap();
}

@Override
public void triggerMisfired(Trigger trigger) {
super.triggerMisfired(trigger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import com.box.l10n.mojito.quartz.QuartzPollableTaskScheduler;
import com.box.l10n.mojito.service.scheduledjob.IScheduledJob;
import com.box.l10n.mojito.service.scheduledjob.ScheduledJobRepository;
import com.box.l10n.mojito.service.thirdparty.ThirdPartySyncJob;
import com.box.l10n.mojito.service.thirdparty.ThirdPartySyncJobInput;
import java.util.ArrayList;
import java.util.List;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
Expand All @@ -16,6 +16,7 @@
import org.springframework.stereotype.Component;

@Component
@DisallowConcurrentExecution
public class ScheduledThirdPartySync implements IScheduledJob {

static Logger logger = LoggerFactory.getLogger(ScheduledThirdPartySync.class);
Expand Down Expand Up @@ -57,10 +58,11 @@ public void execute(JobExecutionContext jobExecutionContext) throws JobExecution
thirdPartySync.setOptions(options);

try {
quartzPollableTaskScheduler
.scheduleJobWithCustomTimeout(
ThirdPartySyncJob.class, thirdPartySync, "thirdPartySync", 3600L)
.get();
Thread.sleep(10000);
// quartzPollableTaskScheduler
// .scheduleJobWithCustomTimeout(
// ThirdPartySyncJob.class, thirdPartySync, "thirdPartySync", 3600L)
// .get();
} catch (Exception e) {
throw new JobExecutionException(e);
}
Expand Down
18 changes: 18 additions & 0 deletions webapp/src/main/resources/db/migration/V68__Add_Scheduled_Job.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TABLE scheduled_job (
id bigint AUTO_INCREMENT PRIMARY KEY,
repository_id bigint NOT NULL,
job_type VARCHAR(255),
cron VARCHAR(15),
properties longtext NOT NULL,
job_status VARCHAR(255) NOT NULL,
start_date TIMESTAMP,
end_date TIMESTAMP,
created_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

ALTER TABLE scheduled_job
ADD UNIQUE KEY UK__REPOSITORY_ID__JOB_TYPE (repository_id, job_type);

alter table `scheduled_job`
add constraint FK__SCHEDULED_JOB__IMPORT_REPOSITORY__ID
foreign key (repository_id) references repository (id);

0 comments on commit fb4e02b

Please sign in to comment.