8000 Fix SystemCommandTasklet to propagate error when exit status is failed by injae-kim · Pull Request #4566 · spring-projects/spring-batch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix SystemCommandTasklet to propagate error when exit status is failed #4566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2023 the original author or authors.
* Copyright 2006-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -60,6 +60,7 @@
* @author Robert Kasanicky
* @author Will Schipp
* @author Mahmoud Ben Hassine
* @author Injae Kim
*/
public class SystemCommandTasklet implements StepExecutionListener, StoppableTasklet, InitializingBean {

Expand Down Expand Up @@ -121,8 +122,15 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
}

if (systemCommandTask.isDone()) {
contribution.setExitStatus(systemProcessExitCodeMapper.getExitStatus(systemCommandTask.get()));
return RepeatStatus.FINISHED;
Integer exitCode = systemCommandTask.get();
ExitStatus exitStatus = systemProcessExitCodeMapper.getExitStatus(exitCode);
contribution.setExitStatus(exitStatus);
if (ExitStatus.FAILED.equals(exitStatus)) {
throw new SystemCommandException("Execution of system command failed with exit code " + exitCode);
}
else {
return RepeatStatus.FINISHED;
}
}
else if (System.currentTimeMillis() - t0 > timeout) {
systemCommandTask.cancel(interruptOnCancel);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2023 the original author or authors.
* Copyright 2008-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -323,9 +323,8 @@ public void testExecuteWithFailedCommandRunnerMockExecution() throws Exception {
tasklet.setCommand(command);
tasklet.afterPropertiesSet();

RepeatStatus exitStatus = tasklet.execute(stepContribution, null);

assertEquals(RepeatStatus.FINISHED, exitStatus);
Exception exception = assertThrows(SystemCommandException.class, () -> tasklet.execute(stepContribution, null));
assertTrue(exception.getMessage().contains("failed with exit code"));
assertEquals(ExitStatus.FAILED, stepContribution.getExitStatus());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AssertionFailed
Expected :exitCode=FAILED;exitDescription=
Actual   :exitCode=EXECUTING;exitDescription=

With L329, this test failed so I just remove it.

Should we set contribution.setExitStatus(FAILED); on SystemCommandTasklet L128?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to update the contribution's exit status in both cases.

Copy link
Contributor Author
6704

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ updated! thank you :)

}

Expand Down
0