From 134f8da6a740c2726082595bf8b3264c67a9c299 Mon Sep 17 00:00:00 2001 From: yijun-lin Date: Fri, 22 Nov 2024 14:35:56 +0000 Subject: [PATCH] add disable jobs property --- .../tasks/impl/jobs/test/TestJobsService.java | 4 +++- .../tasks/impl/jobs/JobsProperties.java | 2 +- .../transferwise/tasks/impl/jobs/JobsService.java | 13 ++++--------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tw-tasks-jobs-test/src/main/java/com/transferwise/tasks/impl/jobs/test/TestJobsService.java b/tw-tasks-jobs-test/src/main/java/com/transferwise/tasks/impl/jobs/test/TestJobsService.java index de6df531..7ccb46ba 100644 --- a/tw-tasks-jobs-test/src/main/java/com/transferwise/tasks/impl/jobs/test/TestJobsService.java +++ b/tw-tasks-jobs-test/src/main/java/com/transferwise/tasks/impl/jobs/test/TestJobsService.java @@ -59,7 +59,9 @@ public boolean hasFinished(ExecuteAsyncHandle handle) { public void reset() { transactionsHelper.withTransaction().asNew().call(() -> { testTasksService.reset(); - initJobs(true); + if (jobsProperties.isAutoStartProcessing()) { + initJobs(true); + } return null; }); } diff --git a/tw-tasks-jobs/src/main/java/com/transferwise/tasks/impl/jobs/JobsProperties.java b/tw-tasks-jobs/src/main/java/com/transferwise/tasks/impl/jobs/JobsProperties.java index 81b1f520..53933a80 100644 --- a/tw-tasks-jobs/src/main/java/com/transferwise/tasks/impl/jobs/JobsProperties.java +++ b/tw-tasks-jobs/src/main/java/com/transferwise/tasks/impl/jobs/JobsProperties.java @@ -14,5 +14,5 @@ public class JobsProperties { private boolean testMode = false; - private boolean jobsDisabled = true; + private boolean autoStartProcessing = true; } diff --git a/tw-tasks-jobs/src/main/java/com/transferwise/tasks/impl/jobs/JobsService.java b/tw-tasks-jobs/src/main/java/com/transferwise/tasks/impl/jobs/JobsService.java index 141e3383..20093c5e 100644 --- a/tw-tasks-jobs/src/main/java/com/transferwise/tasks/impl/jobs/JobsService.java +++ b/tw-tasks-jobs/src/main/java/com/transferwise/tasks/impl/jobs/JobsService.java @@ -36,7 +36,7 @@ public class JobsService implements IJobsService, GracefulShutdownStrategy, Init @Autowired private ITasksService tasksService; @Autowired - private JobsProperties jobsProperties; + protected JobsProperties jobsProperties; @Autowired private ApplicationContext applicationContext; @Autowired(required = false) @@ -47,9 +47,6 @@ public class JobsService implements IJobsService, GracefulShutdownStrategy, Init private final List nonBeanJobs = new ArrayList<>(); public void register(IJob job) { - if (jobsProperties.isJobsDisabled()) { - log.info("All Jobs are disabled, Job {} will not be registered.", job); - } nonBeanJobs.add(job); } @@ -63,7 +60,9 @@ public void afterPropertiesSet() { @Override public void applicationStarted() { - initJobs(false); + if (jobsProperties.isAutoStartProcessing()) { + initJobs(false); + } } @Override @@ -73,10 +72,6 @@ public boolean canShutdown() { @Override public IJob getJobFor(IBaseTask task) { - if (jobsProperties.isJobsDisabled()) { - log.info("All Jobs are disabled. Task {} will not be processed.", task); - return null; - } String jobName = StringUtils.substringAfter(task.getType(), "|"); jobName = StringUtils.substringBefore(jobName, "|"); JobContainer jobContainer = cronTasksMap.get(jobName);