Skip to content

Commit

Permalink
use cronJobMaster for clustered environment
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Dec 7, 2023
1 parent 906b9ec commit 02cdc29
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package manage.service.jobs;

import org.springframework.beans.factory.annotation.Value;
import com.fasterxml.jackson.core.JsonProcessingException;
import manage.conf.Features;
import manage.conf.MetaDataAutoConfiguration;
Expand Down Expand Up @@ -59,21 +59,25 @@ public class MetadataAutoRefreshRunner implements Runnable {

private final FeatureService featureService;

private final boolean cronJobResponsible;

public MetadataAutoRefreshRunner(MetaDataService metaDataService,
ImporterService importerService,
MetaDataAutoConfiguration metaDataAutoConfiguration,
FeatureService featureService) {
FeatureService featureService,
@Value("${cron.node-cron-job-responsible}") boolean cronJobResponsible) {

this.metaDataService = metaDataService;
this.importerService = importerService;
this.metaDataAutoConfiguration = metaDataAutoConfiguration;
this.featureService = featureService;
this.cronJobResponsible = cronJobResponsible;
}

@Override
@Scheduled(cron = "${metadata_import.auto_refresh.cronSchedule}")
public void run() {
if (featureService.isFeatureEnabled(Features.AUTO_REFRESH)) {
if (this.cronJobResponsible && featureService.isFeatureEnabled(Features.AUTO_REFRESH)) {
// Check whether a Thread is already running
if (running || !execLock.tryLock()) {
LOG.warn(LOG_ALREADY_RUNNING);
Expand Down
3 changes: 3 additions & 0 deletions manage-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ metadata_import:
auto_refresh:
cronSchedule: "-"

cron:
node-cron-job-responsible: True

# used by the git plugin
info:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class MetadataAutoRefreshRunnerTest {
@Mock
MetaDataAutoConfiguration metaDataAutoConfiguration;

@InjectMocks
MetadataAutoRefreshRunner autoRefreshRunner;

@Captor
Expand Down Expand Up @@ -90,6 +89,8 @@ void setUp() {
Logger logger = (Logger) LoggerFactory.getLogger(MetadataAutoRefreshRunner.class);
memoryAppender = LogUtils.configureLogger(logger);
memoryAppender.start();

autoRefreshRunner = new MetadataAutoRefreshRunner(metaDataService, importerService, metaDataAutoConfiguration, featureService, true);
}

@Test
Expand Down

0 comments on commit 02cdc29

Please sign in to comment.