-
Notifications
You must be signed in to change notification settings - Fork 5k
[Improvement-17695][ProcedureTask] Support cancel procedure task #17696
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
Changes from 7 commits
6fbe6fb
ff65e4e
d330151
c77c551
7df0688
9fa04cb
3318635
7968379
6403d84
66e93ce
b9fbdba
56ec387
f3a5216
31eeff7
72cca90
6894ab8
5420fd8
5555356
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,6 +43,7 @@ | |||||||||
| import java.sql.CallableStatement; | ||||||||||
| import java.sql.Connection; | ||||||||||
| import java.sql.SQLException; | ||||||||||
| import java.sql.Statement; | ||||||||||
| import java.sql.Types; | ||||||||||
| import java.util.HashMap; | ||||||||||
| import java.util.Map; | ||||||||||
|
|
@@ -60,6 +61,8 @@ public class ProcedureTask extends AbstractTask { | |||||||||
|
|
||||||||||
| private final ProcedureTaskExecutionContext procedureTaskExecutionContext; | ||||||||||
|
|
||||||||||
| private volatile Statement sessionStatement; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * constructor | ||||||||||
| * | ||||||||||
|
|
@@ -105,30 +108,49 @@ public void handle(TaskCallBack taskCallBack) throws TaskException { | |||||||||
| } | ||||||||||
| String proceduerSql = formatSql(sqlParamsMap, paramsMap); | ||||||||||
| // call method | ||||||||||
| try (CallableStatement stmt = connection.prepareCall(proceduerSql)) { | ||||||||||
| try (CallableStatement tmpStatement = connection.prepareCall(proceduerSql)) { | ||||||||||
| sessionStatement = tmpStatement; | ||||||||||
| // set timeout | ||||||||||
| setTimeout(stmt); | ||||||||||
| setTimeout(tmpStatement); | ||||||||||
|
|
||||||||||
| // outParameterMap | ||||||||||
| Map<Integer, Property> outParameterMap = getOutParameterMap(stmt, sqlParamsMap, paramsMap); | ||||||||||
| Map<Integer, Property> outParameterMap = getOutParameterMap(tmpStatement, sqlParamsMap, paramsMap); | ||||||||||
|
|
||||||||||
| stmt.executeUpdate(); | ||||||||||
| tmpStatement.executeUpdate(); | ||||||||||
|
|
||||||||||
| // print the output parameters to the log | ||||||||||
| printOutParameter(stmt, outParameterMap); | ||||||||||
| printOutParameter(tmpStatement, outParameterMap); | ||||||||||
|
|
||||||||||
| setExitStatusCode(EXIT_CODE_SUCCESS); | ||||||||||
| } | ||||||||||
| } catch (Exception e) { | ||||||||||
| if (exitStatusCode == TaskConstants.EXIT_CODE_KILL) { | ||||||||||
| log.info("procedure task has been killed"); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| setExitStatusCode(EXIT_CODE_FAILURE); | ||||||||||
| log.error("procedure task error", e); | ||||||||||
| throw new TaskException("Execute procedure task failed", e); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @Override | ||||||||||
| public void cancel() throws TaskException { | ||||||||||
|
|
||||||||||
| public void cancel() { | ||||||||||
| Statement stmt = this.sessionStatement; | ||||||||||
| if (stmt != null) { | ||||||||||
| try { | ||||||||||
| log.debug("Try to cancel this procedure task"); | ||||||||||
| stmt.cancel(); | ||||||||||
| setExitStatusCode(TaskConstants.EXIT_CODE_KILL); | ||||||||||
|
||||||||||
| stmt.cancel(); | |
| setExitStatusCode(TaskConstants.EXIT_CODE_KILL); | |
| setExitStatusCode(TaskConstants.EXIT_CODE_KILL); | |
| stmt.cancel(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exit status code should be set to EXIT_CODE_KILL before attempting to cancel the statement. If stmt.cancel() throws an exception, the exit status will not be set, which could lead to incorrect task status reporting. Consider moving line 144 before line 143.
good
Outdated
Copilot
AI
Nov 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message refers to "http task" but this is a procedure task. The message should be "Cancel procedure task failed" instead of "Cancel http task failed".
| throw new TaskException("Cancel http task failed", ex); | |
| throw new TaskException("Cancel procedure task failed", ex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message refers to "http task" but this is a procedure task. The message should be "Cancel procedure task failed" instead of "Cancel http task failed".
nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cancel() method signature was changed to remove the
throws TaskExceptiondeclaration, which is inconsistent with the parent class AbstractTask that declarespublic abstract void cancel() throws TaskException;. Even though the implementation throws TaskException on line 148, the signature should maintain the throws declaration for consistency with the parent class and other task implementations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok,good