Skip to content

Commit

Permalink
[CPL-283] Add Disable Jobs Property (#213)
Browse files Browse the repository at this point in the history
* add disable jobs property

* add flag to disable task cleaner and resumer

* disable task resumer and cleaner at application startup

* add new flag for task resumer

* reword java doc

* update changelog and bump version
  • Loading branch information
yijun-lin authored Nov 27, 2024
1 parent 14bdc9b commit c3ceb1d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.46.0 - 2024/11/26

### Added

- Added `autoInitialize` property to enable/disable autoInitialization for job service, preventing registration and resumption when disabled.
- Added `startTasksCleaner` and `startTaskResumer` properties to switch on/off task cleaner and task resumer.

## 1.45.0 - 2024/10/30

### Changed
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=1.45.1
version=1.46.0
org.gradle.internal.http.socketTimeout=120000
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ public class TasksProperties {
*/
private boolean paranoidTasksCleaning = false;

/**
* If true, task cleaner will be started.
*
* <p>It starts to run task cleaner.
*/
private boolean startTasksCleaner = true;

/**
* If true, task resumer will be started automatically.
*
* <p>It starts to run task resumer.
*/
private boolean startTaskResumer = true;

/**
* How many tasks per bucket we are trying to grab at the same time.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ protected void deleteFinishedOldTasks() {

@Override
public void applicationStarted() {
leaderSelector.start();
if (tasksProperties.isStartTasksCleaner()) {
leaderSelector.start();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,10 @@ private ZonedDateTime getMaxStuckTime(ITaskProcessingPolicy taskProcessingPolicy

@Override
public void applicationStarted() {
executorServicesProvider.getGlobalExecutorService().submit(this::resumeTasksForClient);
leaderSelector.start();
if (tasksProperties.isStartTaskResumer()) {
executorServicesProvider.getGlobalExecutorService().submit(this::resumeTasksForClient);
leaderSelector.start();
}
}

@EntryPoint
Expand Down
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.isAutoInitialize()) {
initJobs(true);
}
return null;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public class JobsProperties {
private String processingBucket = IBucketsManager.DEFAULT_ID;

private boolean testMode = false;

private boolean autoInitialize = 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 @@ -60,7 +60,9 @@ public void afterPropertiesSet() {

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

@Override
Expand Down

0 comments on commit c3ceb1d

Please sign in to comment.