Skip to content

Commit

Permalink
Merge pull request #444 from bcgov/feature/GRAD2-2396
Browse files Browse the repository at this point in the history
GRAD2-2396: task is complete.
  • Loading branch information
kamal-mohammed authored Nov 14, 2023
2 parents ca76182 + eb2d217 commit c44a6b0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.util.UUID;

@Configuration
@EnableBatchProcessing
@EnableBatchProcessing(isolationLevelForCreate = "ISOLATION_READ_COMMITTED")
public class BatchJobConfig {

// Partitioning for Regular Grad Run updates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.bc.gov.educ.api.batchgraduation.entity.BatchProcessingEntity;
import ca.bc.gov.educ.api.batchgraduation.service.GradDashboardService;
import net.javacrumbs.shedlock.core.LockAssert;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class BatchJobLauncher {
private Job userScheduledBatchJobRefresher;

@Autowired
@Qualifier("asyncJobLauncher")
private JobLauncher jobLauncher;

@Autowired
Expand All @@ -66,9 +68,10 @@ public class BatchJobLauncher {
private static final String ERROR_MSG = "Error {}";

@Scheduled(cron = "${batch.regalg.cron}")
@SchedulerLock(name = "GraduationBatchJob", lockAtLeastFor = "20s", lockAtMostFor = "1200m")
@SchedulerLock(name = "GraduationBatchJob", lockAtLeastFor = "${batch.system.scheduled.routines.lockAtLeastFor}", lockAtMostFor = "${batch.system.scheduled.routines.lockAtMostFor}")
public void runRegularGradAlgorithm() {
LOGGER.info(BATCH_STARTED);
LockAssert.assertLocked();
JobParametersBuilder builder = new JobParametersBuilder();
builder.addLong(TIME, System.currentTimeMillis()).toJobParameters();
builder.addString(JOB_TRIGGER, BATCH_TRIGGER);
Expand All @@ -86,9 +89,10 @@ public void runRegularGradAlgorithm() {
}

@Scheduled(cron = "${batch.tvrrun.cron}")
@SchedulerLock(name = "tvrBatchJob", lockAtLeastFor = "20s", lockAtMostFor = "1200m")
@SchedulerLock(name = "tvrBatchJob", lockAtLeastFor = "${batch.system.scheduled.routines.lockAtLeastFor}", lockAtMostFor = "${batch.system.scheduled.routines.lockAtMostFor}")
public void runTranscriptVerificationReportProcess() {
LOGGER.info(BATCH_STARTED);
LockAssert.assertLocked();
JobParametersBuilder builder = new JobParametersBuilder();
builder.addLong(TIME, System.currentTimeMillis()).toJobParameters();
builder.addString(JOB_TRIGGER, BATCH_TRIGGER);
Expand All @@ -106,9 +110,10 @@ public void runTranscriptVerificationReportProcess() {
}

@Scheduled(cron = "${batch.distrun.cron}")
@SchedulerLock(name = "DistributionBatchJob", lockAtLeastFor = "10s", lockAtMostFor = "120m")
@SchedulerLock(name = "DistributionBatchJob", lockAtLeastFor = "PT10S", lockAtMostFor = "PT120M")
public void runMonthlyDistributionProcess() {
LOGGER.info(BATCH_STARTED);
LockAssert.assertLocked();
JobParametersBuilder builder = new JobParametersBuilder();
builder.addLong(TIME, System.currentTimeMillis()).toJobParameters();
builder.addString(JOB_TRIGGER, BATCH_TRIGGER);
Expand All @@ -126,9 +131,10 @@ public void runMonthlyDistributionProcess() {
}

@Scheduled(fixedDelayString = "PT30M")
@SchedulerLock(name = "userScheduledBatchJobRefresher", lockAtLeastFor = "10s", lockAtMostFor = "5m")
@SchedulerLock(name = "userScheduledBatchJobRefresher", lockAtLeastFor = "PT10S", lockAtMostFor = "PT5M")
public void refreshUserScheduledQueue() {
LOGGER.info(BATCH_STARTED);
LockAssert.assertLocked();
JobParametersBuilder builder = new JobParametersBuilder();
builder.addLong(TIME, System.currentTimeMillis()).toJobParameters();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public LockableTaskScheduler getScheduler() {

LockManager lockManager = new DefaultLockManager(lockProvider, lockConfigurationExtractor);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(30);
scheduler.setThreadNamePrefix("UserScheduledTask-");
scheduler.initialize();
return new LockableTaskScheduler(scheduler, lockManager);
Expand Down
5 changes: 5 additions & 0 deletions api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ batch:
jobs:
lockAtLeastFor: ${CRON_USER_SCHEDULED_JOBS_LOCK_AT_LEAST_FOR}
lockAtMostFor: ${CRON_USER_SCHEDULED_JOBS_LOCK_AT_MOST_FOR}
system:
scheduled:
routines:
lockAtLeastFor: ${CRON_SYSTEM_SCHEDULED_ROUTINES_LOCK_AT_LEAST_FOR}
lockAtMostFor: ${CRON_SYSTEM_SCHEDULED_ROUTINES_LOCK_AT_MOST_FOR}

#Endpoints
endpoint:
Expand Down
5 changes: 5 additions & 0 deletions api/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ batch:
jobs:
lockAtLeastFor: 10
lockAtMostFor: 180
system:
scheduled:
routines:
lockAtLeastFor: PT1M
lockAtMostFor: PT600M

#Endpoints
endpoint:
Expand Down

0 comments on commit c44a6b0

Please sign in to comment.