From cc0404680b27472e045c27d10b1ef15d24f7c9d4 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 11 Oct 2024 17:35:32 +0100 Subject: [PATCH] Denormalized job type and job status. Added version to base scheduled job properties --- .../box/l10n/mojito/entity/ScheduledJob.java | 49 +++++---- .../entity/ScheduledJobStatusEntity.java | 28 +++++ .../mojito/entity/ScheduledJobTypeEntity.java | 46 ++++++++ .../service/scheduledjob/ScheduledJobDTO.java | 4 +- .../scheduledjob/ScheduledJobListener.java | 14 ++- .../scheduledjob/ScheduledJobManager.java | 34 ++++-- .../scheduledjob/ScheduledJobProperties.java | 12 +- .../scheduledjob/ScheduledJobRepository.java | 2 +- .../ScheduledJobStatusRepository.java | 11 ++ .../ScheduledJobTypeRepository.java | 11 ++ .../jobs/ScheduledThirdPartySync.java | 103 +++--------------- .../ScheduledThirdPartySyncProperties.java | 2 +- 12 files changed, 189 insertions(+), 127 deletions(-) create mode 100644 webapp/src/main/java/com/box/l10n/mojito/entity/ScheduledJobStatusEntity.java create mode 100644 webapp/src/main/java/com/box/l10n/mojito/entity/ScheduledJobTypeEntity.java create mode 100644 webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobStatusRepository.java create mode 100644 webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobTypeRepository.java diff --git a/webapp/src/main/java/com/box/l10n/mojito/entity/ScheduledJob.java b/webapp/src/main/java/com/box/l10n/mojito/entity/ScheduledJob.java index 38fc787ffa..9cfdb0e804 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/entity/ScheduledJob.java +++ b/webapp/src/main/java/com/box/l10n/mojito/entity/ScheduledJob.java @@ -1,16 +1,9 @@ package com.box.l10n.mojito.entity; import com.box.l10n.mojito.json.ObjectMapper; -import com.box.l10n.mojito.rest.View; import com.box.l10n.mojito.service.scheduledjob.ScheduledJobProperties; -import com.box.l10n.mojito.service.scheduledjob.ScheduledJobStatus; -import com.box.l10n.mojito.service.scheduledjob.ScheduledJobType; -import com.fasterxml.jackson.annotation.JsonView; -import jakarta.persistence.Basic; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; @@ -18,9 +11,11 @@ import jakarta.persistence.Table; import jakarta.persistence.Transient; import java.util.Date; +import org.hibernate.envers.Audited; @Entity @Table(name = "scheduled_job") +@Audited public class ScheduledJob extends BaseEntity { @Id private Long id; @@ -28,11 +23,9 @@ public class ScheduledJob extends BaseEntity { @JoinColumn(name = "repository_id") private Repository repository; - @Basic(optional = false) - @Column(name = "job_type") - @Enumerated(EnumType.STRING) - @JsonView(View.Repository.class) - private ScheduledJobType jobType; + @ManyToOne + @JoinColumn(name = "job_type") + private ScheduledJobTypeEntity jobType; @Column(name = "cron") private String cron; @@ -42,11 +35,9 @@ public class ScheduledJob extends BaseEntity { @Column(name = "properties") private String propertiesString; - @Basic(optional = false) - @Column(name = "job_status") - @Enumerated(EnumType.STRING) - @JsonView(View.Repository.class) - private ScheduledJobStatus jobStatus; + @ManyToOne + @JoinColumn(name = "job_status") + private ScheduledJobStatusEntity jobStatus; @Column(name = "start_date") private Date startDate; @@ -54,17 +45,21 @@ public class ScheduledJob extends BaseEntity { @Column(name = "end_date") private Date endDate; + @Column(name = "enabled", nullable = false, columnDefinition = "TINYINT DEFAULT 1") + private Boolean enabled = true; + @PostLoad public void deserializeProperties() { ObjectMapper objectMapper = new ObjectMapper(); try { - this.properties = objectMapper.readValue(propertiesString, jobType.getPropertiesClass()); + this.properties = + objectMapper.readValue(propertiesString, jobType.getEnum().getPropertiesClass()); } catch (Exception e) { throw new RuntimeException( "Failed to deserialize properties '" + propertiesString + "' for class: " - + jobType.getPropertiesClass().getName(), + + jobType.getEnum().getPropertiesClass().getName(), e); } } @@ -87,11 +82,11 @@ public void setRepository(Repository repository) { this.repository = repository; } - public ScheduledJobType getJobType() { + public ScheduledJobTypeEntity getJobType() { return jobType; } - public void setJobType(ScheduledJobType jobType) { + public void setJobType(ScheduledJobTypeEntity jobType) { this.jobType = jobType; } @@ -126,11 +121,11 @@ public void setPropertiesString(String properties) { this.propertiesString = properties; } - public ScheduledJobStatus getJobStatus() { + public ScheduledJobStatusEntity getJobStatus() { return jobStatus; } - public void setJobStatus(ScheduledJobStatus jobStatus) { + public void setJobStatus(ScheduledJobStatusEntity jobStatus) { this.jobStatus = jobStatus; } @@ -149,4 +144,12 @@ public Date getEndDate() { public void setEndDate(Date endDate) { this.endDate = endDate; } + + public Boolean getEnabled() { + return enabled; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } } diff --git a/webapp/src/main/java/com/box/l10n/mojito/entity/ScheduledJobStatusEntity.java b/webapp/src/main/java/com/box/l10n/mojito/entity/ScheduledJobStatusEntity.java new file mode 100644 index 0000000000..51427717fe --- /dev/null +++ b/webapp/src/main/java/com/box/l10n/mojito/entity/ScheduledJobStatusEntity.java @@ -0,0 +1,28 @@ +package com.box.l10n.mojito.entity; + +import static org.hibernate.envers.RelationTargetAuditMode.NOT_AUDITED; + +import com.box.l10n.mojito.rest.View; +import com.box.l10n.mojito.service.scheduledjob.ScheduledJobStatus; +import com.fasterxml.jackson.annotation.JsonView; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import org.hibernate.envers.Audited; + +@Entity +@Table(name = "scheduled_job_status") +@Audited(targetAuditMode = NOT_AUDITED) +public class ScheduledJobStatusEntity extends BaseEntity { + @Id private Long id; + + @Basic(optional = false) + @Column(name = "name") + @Enumerated(EnumType.STRING) + @JsonView(View.Repository.class) + private ScheduledJobStatus jobStatus; +} diff --git a/webapp/src/main/java/com/box/l10n/mojito/entity/ScheduledJobTypeEntity.java b/webapp/src/main/java/com/box/l10n/mojito/entity/ScheduledJobTypeEntity.java new file mode 100644 index 0000000000..62fcc6ad1f --- /dev/null +++ b/webapp/src/main/java/com/box/l10n/mojito/entity/ScheduledJobTypeEntity.java @@ -0,0 +1,46 @@ +package com.box.l10n.mojito.entity; + +import static org.hibernate.envers.RelationTargetAuditMode.NOT_AUDITED; + +import com.box.l10n.mojito.rest.View; +import com.box.l10n.mojito.service.scheduledjob.ScheduledJobType; +import com.fasterxml.jackson.annotation.JsonView; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import org.hibernate.envers.Audited; + +@Entity +@Table(name = "scheduled_job_type") +@Audited(targetAuditMode = NOT_AUDITED) +public class ScheduledJobTypeEntity extends BaseEntity { + @Id private Long id; + + @Basic(optional = false) + @Column(name = "name") + @Enumerated(EnumType.STRING) + @JsonView(View.Repository.class) + private ScheduledJobType jobType; + + @Override + public Long getId() { + return id; + } + + @Override + public void setId(Long id) { + this.id = id; + } + + public ScheduledJobType getEnum() { + return jobType; + } + + public void setEnum(ScheduledJobType jobType) { + this.jobType = jobType; + } +} diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobDTO.java b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobDTO.java index 8e3a77d5df..25a8851d3f 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobDTO.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobDTO.java @@ -16,10 +16,10 @@ public class ScheduledJobDTO { public ScheduledJobDTO(ScheduledJob scheduledJob) { this.id = scheduledJob.getId(); this.repository = scheduledJob.getRepository().getName(); - this.jobType = scheduledJob.getJobType(); + // this.jobType = scheduledJob.getJobType(); this.cron = scheduledJob.getCron(); this.properties = scheduledJob.getProperties(); - this.jobStatus = scheduledJob.getJobStatus(); + // this.jobStatus = scheduledJob.getJobStatus(); this.startDate = scheduledJob.getStartDate(); this.endDate = scheduledJob.getEndDate(); } diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobListener.java b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobListener.java index 385658baf7..105ea9c7ea 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobListener.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobListener.java @@ -13,9 +13,13 @@ public class ScheduledJobListener extends JobListenerSupport { static Logger logger = LoggerFactory.getLogger(ScheduledJobListener.class); private final ScheduledJobRepository scheduledJobRepository; + private final ScheduledJobStatusRepository scheduledJobStatusRepository; - public ScheduledJobListener(ScheduledJobRepository scheduledJobRepository) { + public ScheduledJobListener( + ScheduledJobRepository scheduledJobRepository, + ScheduledJobStatusRepository scheduledJobStatusRepository) { this.scheduledJobRepository = scheduledJobRepository; + this.scheduledJobStatusRepository = scheduledJobStatusRepository; } @Override @@ -28,7 +32,8 @@ public void jobToBeExecuted(JobExecutionContext context) { ScheduledJob scheduledJob = scheduledJobRepository.findByJobKey(context.getJobDetail().getKey()); - scheduledJob.setJobStatus(ScheduledJobStatus.IN_PROGRESS); + scheduledJob.setJobStatus( + scheduledJobStatusRepository.findByEnum(ScheduledJobStatus.IN_PROGRESS)); scheduledJob.setStartDate(new Date()); scheduledJobRepository.save(scheduledJob); @@ -43,10 +48,11 @@ public void jobWasExecuted(JobExecutionContext context, JobExecutionException jo IScheduledJob jobInstance = (IScheduledJob) context.getJobInstance(); if (jobException == null) { - scheduledJob.setJobStatus(ScheduledJobStatus.SUCCEEDED); + scheduledJob.setJobStatus( + scheduledJobStatusRepository.findByEnum(ScheduledJobStatus.SUCCEEDED)); jobInstance.onSuccess(context); } else { - scheduledJob.setJobStatus(ScheduledJobStatus.FAILED); + scheduledJob.setJobStatus(scheduledJobStatusRepository.findByEnum(ScheduledJobStatus.FAILED)); jobInstance.onFailure(context, jobException); } diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobManager.java b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobManager.java index 073d26e84f..23d3d368b8 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobManager.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobManager.java @@ -35,6 +35,8 @@ public class ScheduledJobManager { @Autowired ThirdPartySyncJobsConfig thirdPartySyncJobsConfig; @Autowired QuartzSchedulerManager schedulerManager; @Autowired ScheduledJobRepository scheduledJobRepository; + @Autowired ScheduledJobStatusRepository scheduledJobStatusRepository; + @Autowired ScheduledJobTypeRepository scheduledJobTypeRepository; @Autowired RepositoryRepository repositoryRepository; /* Quartz scheduler dedicated to scheduled jobs using in memory data source */ @@ -45,7 +47,8 @@ public void init() throws ClassNotFoundException, SchedulerException { // Attach Job and Trigger listeners on the 'scheduledJobs' scheduler getScheduler() .getListenerManager() - .addJobListener(new ScheduledJobListener(scheduledJobRepository)); + .addJobListener( + new ScheduledJobListener(scheduledJobRepository, scheduledJobStatusRepository)); getScheduler() .getListenerManager() .addTriggerListener(new ScheduledJobTriggerListener(scheduledJobRepository)); @@ -65,7 +68,7 @@ public void init() throws ClassNotFoundException, SchedulerException { } // Clean up quartz jobs for this scheduler that are not in the DB. - cleanupDB(); + // cleanupDB(); scheduleJobs(); } @@ -73,7 +76,7 @@ public void cleanupDB() throws SchedulerException { for (JobKey jobKey : getScheduler().getJobKeys(GroupMatcher.anyGroup())) { if (scheduledJobRepository.findByJobKey(jobKey) == null) { logger.info( - "Removing {} job for repo ID: {} as it's no longer the 'scheduled_job' table.", + "Removing {} job for repo ID: {} as it's no longer in the 'scheduled_job' table.", jobKey.getGroup(), jobKey.getName()); getScheduler().deleteJob(jobKey); @@ -90,8 +93,11 @@ public void pushJobToDB(ThirdPartySyncJobConfig jobConfig) { ScheduledJob scheduledJob = new ScheduledJob(); scheduledJob.setCron(jobConfig.getCron()); scheduledJob.setRepository(repositoryRepository.findByName(jobConfig.getRepository())); - scheduledJob.setJobStatus(ScheduledJobStatus.SCHEDULED); - scheduledJob.setJobType(ScheduledJobType.THIRD_PARTY_SYNC); + scheduledJob.setJobStatus( + scheduledJobStatusRepository.findByEnum(ScheduledJobStatus.IN_PROGRESS)); + + scheduledJob.setJobType( + scheduledJobTypeRepository.findByEnum(ScheduledJobType.THIRD_PARTY_SYNC)); ScheduledThirdPartySyncProperties thirdPartySyncProperties = new ScheduledThirdPartySyncProperties(); @@ -124,19 +130,28 @@ public void scheduleJobs() throws ClassNotFoundException, SchedulerException { // Retrieve job class from enum value e.g. THIRD_PARTY_SYNC -> ScheduledThirdPartySync Class jobType = - loadJobClass(scheduledJob.getJobType().getJobClassName()); + loadJobClass(scheduledJob.getJobType().getEnum().getJobClassName()); JobDetail job = JobBuilder.newJob(jobType).withIdentity(jobKey).build(); Trigger trigger = buildTrigger(jobKey, scheduledJob.getCron(), triggerKey); + if (!scheduledJob.getEnabled()) { + // The job is disabled and exists in Quartz, pause it + if (getScheduler().checkExists(jobKey)) { + getScheduler().pauseJob(jobKey); + } + return; + } + if (getScheduler().checkExists(jobKey)) { getScheduler().rescheduleJob(triggerKey, trigger); } else { getScheduler().scheduleJob(job, trigger); } - scheduledJob.setJobStatus(ScheduledJobStatus.SCHEDULED); + scheduledJob.setJobStatus( + scheduledJobStatusRepository.findByEnum(ScheduledJobStatus.SCHEDULED)); scheduledJobRepository.save(scheduledJob); } } @@ -151,13 +166,14 @@ public Trigger buildTrigger(JobKey jobKey, String cronExpression, TriggerKey tri private JobKey getJobKey(ScheduledJob scheduledJob) { return new JobKey( - scheduledJob.getRepository().getId().toString(), scheduledJob.getJobType().toString()); + scheduledJob.getRepository().getId().toString(), + scheduledJob.getJobType().getEnum().toString()); } private TriggerKey getTriggerKey(ScheduledJob scheduledJob) { return new TriggerKey( "trigger_" + scheduledJob.getRepository().getId().toString(), - scheduledJob.getJobType().toString()); + scheduledJob.getJobType().getEnum().toString()); } public Scheduler getScheduler() { diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobProperties.java b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobProperties.java index 3049c16e16..08007e06cf 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobProperties.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobProperties.java @@ -1,3 +1,13 @@ package com.box.l10n.mojito.service.scheduledjob; -public interface ScheduledJobProperties {} +public abstract class ScheduledJobProperties { + private int version = 1; + + public int getVersion() { + return version; + } + + public void setVersion(int version) { + this.version = version; + } +} diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobRepository.java b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobRepository.java index 41e822272e..04a3eb621e 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobRepository.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobRepository.java @@ -9,7 +9,7 @@ public interface ScheduledJobRepository extends JpaRepository { + @Query("SELECT sjs FROM ScheduledJobStatusEntity sjs " + "WHERE sjs.jobStatus = :jobStatus") + ScheduledJobStatusEntity findByEnum(ScheduledJobStatus jobStatus); +} diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobTypeRepository.java b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobTypeRepository.java new file mode 100644 index 0000000000..d948573007 --- /dev/null +++ b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobTypeRepository.java @@ -0,0 +1,11 @@ +package com.box.l10n.mojito.service.scheduledjob; + +import com.box.l10n.mojito.entity.ScheduledJobTypeEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +public interface ScheduledJobTypeRepository extends JpaRepository { + @Query("SELECT sjt FROM ScheduledJobTypeEntity sjt " + "WHERE sjt.jobType = :jobType") + ScheduledJobTypeEntity findByEnum( + com.box.l10n.mojito.service.scheduledjob.ScheduledJobType jobType); +} diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/jobs/ScheduledThirdPartySync.java b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/jobs/ScheduledThirdPartySync.java index 7eca49ee09..53f34cb5ea 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/jobs/ScheduledThirdPartySync.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/jobs/ScheduledThirdPartySync.java @@ -1,30 +1,16 @@ package com.box.l10n.mojito.service.scheduledjob.jobs; -import static com.box.l10n.mojito.slack.SlackClient.COLOR_DANGER; - import com.box.l10n.mojito.entity.ScheduledJob; import com.box.l10n.mojito.quartz.QuartzPollableTaskScheduler; -import com.box.l10n.mojito.service.pollableTask.PollableFuture; -import com.box.l10n.mojito.service.pollableTask.PollableTaskBlobStorage; 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 com.box.l10n.mojito.slack.SlackClient; -import com.box.l10n.mojito.slack.SlackClientException; -import com.box.l10n.mojito.slack.SlackClients; -import com.box.l10n.mojito.slack.request.Attachment; -import com.box.l10n.mojito.slack.request.Field; -import com.box.l10n.mojito.slack.request.Message; -import java.util.ArrayList; -import java.util.List; import org.quartz.DisallowConcurrentExecution; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component @@ -35,26 +21,11 @@ public class ScheduledThirdPartySync implements IScheduledJob { @Autowired QuartzPollableTaskScheduler quartzPollableTaskScheduler; @Autowired private ScheduledJobRepository scheduledJobRepository; - @Autowired SlackClients slackClients; - - @Value("${l10n.scheduledJobs.slack.clientId:}") - private String slackClientId; - - @Value("${l10n.scheduledJobs.slack.channel:}") - private String slackChannel; public static int runAmount = 0; - @Autowired PollableTaskBlobStorage pollableTaskBlobStorage; - @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { - if (runAmount == 1) { - return; - } - - runAmount++; - ScheduledJob job = scheduledJobRepository.findByJobKey(jobExecutionContext.getJobDetail().getKey()); ScheduledThirdPartySyncProperties properties = @@ -62,7 +33,12 @@ public void execute(JobExecutionContext jobExecutionContext) throws JobExecution logger.info("Third party sync for repository {} has started.", job.getRepository().getName()); - List options = new ArrayList<>(); + if (runAmount == 0) { + return; + } + + runAmount++; + ThirdPartySyncJobInput thirdPartySync = new ThirdPartySyncJobInput(); thirdPartySync.setRepositoryId(job.getRepository().getId()); thirdPartySync.setThirdPartyProjectId(properties.getThirdPartyProjectId()); @@ -83,17 +59,17 @@ public void execute(JobExecutionContext jobExecutionContext) throws JobExecution ? null : properties.getIncludeTextUnitsWithPattern()); - thirdPartySync.setOptions(options); - - try { - PollableFuture task = - quartzPollableTaskScheduler.scheduleJobWithCustomTimeout( - ThirdPartySyncJob.class, thirdPartySync, "thirdPartySync", 3600L); - jobExecutionContext.put("PollableTaskId", task.getPollableTask().getId()); - task.get(); - } catch (Exception e) { - throw new JobExecutionException(e); - } + thirdPartySync.setOptions(properties.getOptions()); + + // try { + // PollableFuture task = + // quartzPollableTaskScheduler.scheduleJobWithCustomTimeout( + // ThirdPartySyncJob.class, thirdPartySync, "thirdPartySync", 3600L); + // jobExecutionContext.put("PollableTaskId", task.getPollableTask().getId()); + // task.get(); + // } catch (Exception e) { + // throw new JobExecutionException(e); + // } } @Override @@ -115,50 +91,5 @@ public void onFailure(JobExecutionContext context, JobExecutionException jobExce polladbleTaskId); // TODO: Notifications - if (slackClientId.isEmpty() || slackChannel.isEmpty()) return; - Message warning = buildSlackMessage(job, properties, jobException, polladbleTaskId); - - SlackClient slackClient = slackClients.getById(slackClientId); - try { - slackClient.sendInstantMessage(warning); - } catch (SlackClientException e) { - logger.error( - "Slack client failed to send warning message with id '{}' and channel '{}'", - slackClientId, - slackChannel, - e); - } - } - - private Message buildSlackMessage( - ScheduledJob job, - ScheduledThirdPartySyncProperties properties, - JobExecutionException jobException, - Long pollableId) { - Message warning = new Message(); - warning.setText(""); - warning.setChannel(slackChannel); - - Attachment attachment = new Attachment(); - attachment.setTitle("Mojito | Third Party Sync failed for " + job.getRepository().getName()); - attachment.setText("This scheduled job has failed, visit /api/pollableTasks/" + pollableId); - - List fields = new ArrayList<>(); - fields.add(createField("Repository", job.getRepository().getName())); - fields.add(createField("Third Party ID", properties.getThirdPartyProjectId())); - - fields.add(createField("Error", jobException.getMessage())); - - attachment.setFields(fields); - attachment.setColor(COLOR_DANGER); - warning.getAttachments().add(attachment); - return warning; - } - - private Field createField(String title, String value) { - Field field = new Field(); - field.setTitle(title); - field.setValue(value); - return field; } } diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/jobs/ScheduledThirdPartySyncProperties.java b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/jobs/ScheduledThirdPartySyncProperties.java index 584d4f57c4..2d8f23c8d9 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/jobs/ScheduledThirdPartySyncProperties.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/scheduledjob/jobs/ScheduledThirdPartySyncProperties.java @@ -4,7 +4,7 @@ import com.box.l10n.mojito.service.scheduledjob.ScheduledJobProperties; import java.util.List; -public class ScheduledThirdPartySyncProperties implements ScheduledJobProperties { +public class ScheduledThirdPartySyncProperties extends ScheduledJobProperties { private String thirdPartyProjectId; private List actions; private String pluralSeparator;