Skip to content

Commit

Permalink
refactor: Moved pool option to commands that require it
Browse files Browse the repository at this point in the history
  • Loading branch information
jruaux committed Aug 30, 2024
1 parent be1c07e commit dd2f291
Show file tree
Hide file tree
Showing 53 changed files with 1,596 additions and 1,358 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ subprojects { subproj ->
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.platform:junit-platform-launcher'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.slf4j:slf4j-simple'
testImplementation group: 'com.redis', name: 'testcontainers-redis', version: testcontainersRedisVersion
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.redis.riot.core;

import java.util.concurrent.Callable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

@Command
public abstract class AbstractCallableCommand extends BaseCommand implements Callable<Integer> {

@Option(names = "--help", usageHelp = true, description = "Show this help message and exit.")
private boolean helpRequested;

protected Logger log;

@Override
public Integer call() throws Exception {
if (log == null) {
log = LoggerFactory.getLogger(getClass());
}
execute();
return 0;
}

protected abstract void execute() throws Exception;

public Logger getLog() {
return log;
}

public void setLog(Logger log) {
this.log = log;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Iterator;
import java.util.List;

import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.ItemWriteListener;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
Expand Down Expand Up @@ -36,6 +37,7 @@
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import com.redis.spring.batch.JobUtils;
import com.redis.spring.batch.item.AbstractAsyncItemReader;
Expand All @@ -47,7 +49,7 @@
import picocli.CommandLine.Option;

@Command
public abstract class AbstractJobCommand extends AbstractCommand {
public abstract class AbstractJobCommand extends AbstractCallableCommand {

public static final String DEFAULT_JOB_REPOSITORY_NAME = "riot";

Expand Down Expand Up @@ -96,7 +98,11 @@ protected void execute() throws Exception {
JobExecution jobExecution = jobLauncher.run(job(), new JobParameters());
if (JobUtils.isFailed(jobExecution.getExitStatus())) {
for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
if (JobUtils.isFailed(stepExecution.getExitStatus())) {
ExitStatus stepExitStatus = stepExecution.getExitStatus();
if (JobUtils.isFailed(stepExitStatus)) {
if (CollectionUtils.isEmpty(stepExecution.getFailureExceptions())) {
throw new JobExecutionException(stepExitStatus.getExitDescription());
}
throw wrapException(stepExecution.getFailureExceptions());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import java.util.Map;

import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Option;
import picocli.CommandLine.Spec;

@Command(usageHelpAutoWidth = true, mixinStandardHelpOptions = true, abbreviateSynopsis = true)
public abstract class BaseCommand {
public class BaseCommand {

static {
if (System.getenv().containsKey("RIOT_NO_COLOR")) {
Expand All @@ -19,6 +20,9 @@ public abstract class BaseCommand {
@Spec
protected CommandSpec commandSpec;

@Mixin
LoggingMixin loggingMixin;

@Option(names = "-D", paramLabel = "<key=value>", description = "Sets a System property.", mapFallbackValue = "", hidden = true)
void setProperty(Map<String, String> props) {
props.forEach(System::setProperty);
Expand Down
169 changes: 0 additions & 169 deletions core/riot-core/src/main/java/com/redis/riot/core/LoggingArgs.java

This file was deleted.

Loading

0 comments on commit dd2f291

Please sign in to comment.