Skip to content

Commit

Permalink
Extract a function in the DefaultJobManager to determine if a job is …
Browse files Browse the repository at this point in the history
…applicable for the execution
  • Loading branch information
filiphr committed Aug 10, 2023
1 parent 480e244 commit 19f923e
Showing 1 changed file with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public DefaultJobManager(JobServiceConfiguration jobServiceConfiguration) {
@Override
public void createAsyncJob(JobEntity jobEntity, boolean exclusive) {
// When the async executor is activated, the job is directly passed on to the async executor thread
if (isAsyncExecutorActive()) {
if (isJobApplicableForExecutorExecution(jobEntity)) {
internalCreateLockedAsyncJob(jobEntity, exclusive);

} else {
Expand All @@ -93,20 +93,32 @@ public void scheduleAsyncJob(JobEntity jobEntity) {
}

protected void triggerExecutorIfNeeded(JobEntity jobEntity) {
// When the async executor is activated, the job is directly passed on to the async executor thread
if (isAsyncExecutorActive()) {
if (jobServiceConfiguration.getEnabledJobCategories() != null && !jobServiceConfiguration.getEnabledJobCategories().isEmpty()) {
if (StringUtils.isEmpty(jobEntity.getCategory())) {
return;
}
if (!jobServiceConfiguration.getEnabledJobCategories().contains(jobEntity.getCategory())) {
return;
}
}
if (isJobApplicableForExecutorExecution(jobEntity)) {
hintAsyncExecutor(jobEntity);
}
}

protected boolean isJobApplicableForExecutorExecution(JobEntity jobEntity) {
if (!isAsyncExecutorActive()) {
// If the async executor is not active then it should not be hinted
return false;
}
List<String> enabledJobCategories = jobServiceConfiguration.getEnabledJobCategories();
if (enabledJobCategories == null || enabledJobCategories.isEmpty()) {
// If there are no job categories then we need to hint it
return true;
}

String category = jobEntity.getCategory();
if (StringUtils.isEmpty(category)) {
// If the job has no category then we should not hint it, another node needs to run it
return false;
}

// Finally, the job should be hinted if the enabled job categories contain the job category
return enabledJobCategories.contains(category);
}

@Override
public void scheduleTimerJob(TimerJobEntity timerJob) {
jobServiceConfiguration.getTimerJobScheduler().scheduleTimerJob(timerJob);
Expand Down Expand Up @@ -669,14 +681,6 @@ protected void internalCreateAsyncJob(JobEntity jobEntity, boolean exclusive) {
protected void internalCreateLockedAsyncJob(JobEntity jobEntity, boolean exclusive) {
fillDefaultAsyncJobInfo(jobEntity, exclusive);

if (StringUtils.isNotEmpty(jobEntity.getCategory())) {
if (jobServiceConfiguration.getEnabledJobCategories() != null &&
!jobServiceConfiguration.getEnabledJobCategories().contains(jobEntity.getCategory())) {

return;
}
}

setLockTimeAndOwner(getAsyncExecutor(), jobEntity);
}

Expand Down

0 comments on commit 19f923e

Please sign in to comment.