Skip to content

Commit

Permalink
add disable jobs property
Browse files Browse the repository at this point in the history
  • Loading branch information
yijun-lin committed Nov 22, 2024
1 parent e416c56 commit 134f8da
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public class JobsProperties {

private boolean testMode = false;

private boolean jobsDisabled = true;
private boolean autoStartProcessing = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -47,9 +47,6 @@ public class JobsService implements IJobsService, GracefulShutdownStrategy, Init
private final List<IJob> 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);
}

Expand All @@ -63,7 +60,9 @@ public void afterPropertiesSet() {

@Override
public void applicationStarted() {
initJobs(false);
if (jobsProperties.isAutoStartProcessing()) {
initJobs(false);
}
}

@Override
Expand All @@ -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);
Expand Down

0 comments on commit 134f8da

Please sign in to comment.