Skip to content

Commit

Permalink
Changes cron job to hourly (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
analoo authored Oct 23, 2024
1 parent 81f2c9e commit 3ccdb62
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
9 changes: 4 additions & 5 deletions src/main/java/org/ilgcc/jobs/TransmissionsRecurringJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import org.jobrunr.jobs.annotations.Recurring;
import org.jobrunr.scheduling.JobScheduler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

@Slf4j
@ConditionalOnProperty(name="il-gcc.dts.expand-existing-provider-flow", havingValue = "true")
@Service
public class TransmissionsRecurringJob {

Expand All @@ -32,15 +34,13 @@ public class TransmissionsRecurringJob {
private final UploadedDocumentTransmissionJob uploadedDocumentTransmissionJob;
private final PdfService pdfService;
private final CloudFileRepository cloudFileRepository;
private Boolean expandExistingProviderFlow;
private final PdfTransmissionJob pdfTransmissionJob;
private final EnqueueDocumentTransfer enqueueDocumentTransfer;

public TransmissionsRecurringJob(S3PresignService s3PresignService,
TransmissionRepositoryService transmissionRepositoryService, UserFileRepositoryService userFileRepositoryService,
UploadedDocumentTransmissionJob uploadedDocumentTransmissionJob, PdfService pdfService,
CloudFileRepository cloudFileRepository, PdfTransmissionJob pdfTransmissionJob,
@Value("${il-gcc.dts.expand-existing-provider-flow}") Boolean expandExistingProviderFlow,
EnqueueDocumentTransfer enqueueDocumentTransfer) {
this.s3PresignService = s3PresignService;
this.transmissionRepositoryService = transmissionRepositoryService;
Expand All @@ -49,11 +49,10 @@ public TransmissionsRecurringJob(S3PresignService s3PresignService,
this.pdfService = pdfService;
this.cloudFileRepository = cloudFileRepository;
this.pdfTransmissionJob = pdfTransmissionJob;
this.expandExistingProviderFlow = expandExistingProviderFlow;
this.enqueueDocumentTransfer = enqueueDocumentTransfer;
}

@Recurring(id = "no-provider-response-job", cron = "* * * * *")
@Recurring(id = "no-provider-response-job", cron = "0 * * * *")
@Job(name = "No provider response job")
public void noProviderResponseJob() {
List<Submission> submissionsWithoutTransmissions = transmissionRepositoryService.findSubmissionsWithoutTransmission();
Expand All @@ -63,7 +62,7 @@ public void noProviderResponseJob() {

List<Submission> expiredSubmissionsWithNoTransmission = submissionsWithoutTransmissions.stream()
.filter(submission -> providerApplicationHasExpired(submission, todaysDate)).toList();
if (expiredSubmissionsWithNoTransmission.isEmpty() || !expandExistingProviderFlow) {
if (expiredSubmissionsWithNoTransmission.isEmpty()) {
return;
} else {
log.info(String.format("Running the 'No provider response job' for %s expired submissions",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.ilgcc.jobs;

import org.ilgcc.app.IlGCCApplication;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;

import static org.junit.jupiter.api.Assertions.assertFalse;

@SpringBootTest(
classes = IlGCCApplication.class,
properties = "il-gcc.dts.expand-existing-provider-flow=false"
)
@ActiveProfiles("test")
public class TransmissionsRecurringJobFlagOffTest {

@Autowired
private ApplicationContext context;

@Test
public void transmissionRecurringJobDisabledWhenFlagIsOff() {
assertFalse(context.containsBean("transmissionsRecurringJob"));
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package org.ilgcc.jobs;

import static org.ilgcc.app.utils.enums.TransmissionStatus.Queued;
import static org.ilgcc.app.utils.enums.TransmissionType.APPLICATION_PDF;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import formflow.library.data.Submission;
import formflow.library.data.SubmissionRepository;
import formflow.library.data.UserFileRepositoryService;
import formflow.library.file.CloudFileRepository;
import formflow.library.pdf.PdfService;
import java.time.OffsetDateTime;
import java.util.Date;
import org.ilgcc.app.IlGCCApplication;
import org.ilgcc.app.data.Transmission;
Expand All @@ -18,20 +25,17 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.time.OffsetDateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;

import static org.ilgcc.app.utils.enums.TransmissionStatus.Queued;
import static org.ilgcc.app.utils.enums.TransmissionType.APPLICATION_PDF;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

@SpringBootTest(classes = IlGCCApplication.class)
@SpringBootTest(
classes = IlGCCApplication.class,
properties = "il-gcc.dts.expand-existing-provider-flow=true"
)
@ActiveProfiles("test")
public class TransmissionsRecurringJobTest {
public class TransmissionsRecurringJobFlagOnTest {

@Autowired
private SubmissionRepository submissionRepository;
Expand Down Expand Up @@ -59,6 +63,9 @@ public class TransmissionsRecurringJobTest {
@Mock
private PdfTransmissionJob pdfTransmissionJob;

@Autowired
private ApplicationContext context;

@Mock
private EnqueueDocumentTransfer enqueueDocumentTransfer;

Expand All @@ -82,7 +89,6 @@ void setUp() {
pdfService,
cloudFileRepository,
pdfTransmissionJob,
true,
enqueueDocumentTransfer
);
}
Expand All @@ -94,30 +100,10 @@ protected void clearSubmissions() {
}

@Test
void enqueueDocumentTransferWillNotRunIfFlagIsOff() {
expiredSubmission = new SubmissionTestBuilder()
.withParentDetails()
.withSubmittedAtDate(OffsetDateTime.now().minusDays(7))
.withFlow("gcc")
.build();
submissionRepository.save(expiredSubmission);

transmissionsRecurringJob = new TransmissionsRecurringJob(
s3PresignService,
transmissionRepositoryService,
userFileRepositoryService,
uploadedDocumentTransmissionJob,
pdfService,
cloudFileRepository,
pdfTransmissionJob,
false,
enqueueDocumentTransfer
);

transmissionsRecurringJob.noProviderResponseJob();

verifyNoInteractions(enqueueDocumentTransfer);
public void transmissionRecurringJobEnabledWhenFlagIsOn() {
assertTrue(context.containsBean("transmissionsRecurringJob"));
}

@Test
void enqueueDocumentTransferIsOnlyCalledOnExpiredSubmissions() {
unexpiredSubmission = new SubmissionTestBuilder()
Expand Down

0 comments on commit 3ccdb62

Please sign in to comment.