This is an automated email from the ASF dual-hosted git repository.
djoseph pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-runtimes.git
The following commit(s) were added to refs/heads/main by this push:
new d6e0aa051c [incubator-kie-issues#2255] Sync service task not setting
process to ERROR state (#4199)
d6e0aa051c is described below
commit d6e0aa051c80674c43fd3033010b0a68fc22eac1
Author: Deepak Joseph <[email protected]>
AuthorDate: Tue Mar 10 13:36:52 2026 +0530
[incubator-kie-issues#2255] Sync service task not setting process to ERROR
state (#4199)
* sync service task fix
* UnitOfWorkExecutor for transaction and non transactional execution
* UnitOfWorkExecutor for transaction and non transactional execution
* Fix for race conditions
* Simplying catch clauses to deal with RuntimeExceptions
* update
---
...xecutor.java => DefaultUnitOfWorkExecutor.java} | 21 ++++--------
...ava => TransactionAwareUnitOfWorkExecutor.java} | 25 ++++----------
.../kogito/services/uow/UnitOfWorkExecutor.java | 39 +++++++++-------------
.../workflow/instance/impl/NodeInstanceImpl.java | 10 ++++++
.../kie/kogito/codegen/process/ProcessCodegen.java | 13 +++++++-
...itOfWorkExecutorInitializerQuarkusTemplate.java | 34 +++++++++++++++++++
...nitOfWorkExecutorInitializerSpringTemplate.java | 32 ++++++++++++++++++
7 files changed, 115 insertions(+), 59 deletions(-)
diff --git
a/api/kogito-services/src/main/java/org/kie/kogito/services/uow/UnitOfWorkExecutor.java
b/api/kogito-services/src/main/java/org/kie/kogito/services/uow/DefaultUnitOfWorkExecutor.java
similarity index 76%
copy from
api/kogito-services/src/main/java/org/kie/kogito/services/uow/UnitOfWorkExecutor.java
copy to
api/kogito-services/src/main/java/org/kie/kogito/services/uow/DefaultUnitOfWorkExecutor.java
index 07127db117..0ba1067932 100644
---
a/api/kogito-services/src/main/java/org/kie/kogito/services/uow/UnitOfWorkExecutor.java
+++
b/api/kogito-services/src/main/java/org/kie/kogito/services/uow/DefaultUnitOfWorkExecutor.java
@@ -24,14 +24,11 @@ import
org.kie.kogito.process.ProcessInstanceExecutionException;
import org.kie.kogito.uow.UnitOfWork;
import org.kie.kogito.uow.UnitOfWorkManager;
-public class UnitOfWorkExecutor {
+public class DefaultUnitOfWorkExecutor extends UnitOfWorkExecutor {
- private UnitOfWorkExecutor() {
-
- }
-
- public static <T> T executeInUnitOfWork(UnitOfWorkManager uowManager,
Supplier<T> supplier) {
- T result = null;
+ @Override
+ public <T> T execute(UnitOfWorkManager uowManager, Supplier<T> supplier) {
+ T result;
UnitOfWork uow = uowManager.newUnitOfWork();
try {
@@ -44,15 +41,9 @@ public class UnitOfWorkExecutor {
} catch (ProcessInstanceExecutionException e) {
uow.end();
throw e;
- } catch (Exception e) {
+ } catch (RuntimeException e) {
uow.abort();
- if (e instanceof RuntimeException) {
- throw (RuntimeException) e;
- } else {
- throw new RuntimeException(e);
- }
+ throw e;
}
-
}
-
}
diff --git
a/api/kogito-services/src/main/java/org/kie/kogito/services/uow/UnitOfWorkExecutor.java
b/api/kogito-services/src/main/java/org/kie/kogito/services/uow/TransactionAwareUnitOfWorkExecutor.java
similarity index 68%
copy from
api/kogito-services/src/main/java/org/kie/kogito/services/uow/UnitOfWorkExecutor.java
copy to
api/kogito-services/src/main/java/org/kie/kogito/services/uow/TransactionAwareUnitOfWorkExecutor.java
index 07127db117..08cb152e2b 100644
---
a/api/kogito-services/src/main/java/org/kie/kogito/services/uow/UnitOfWorkExecutor.java
+++
b/api/kogito-services/src/main/java/org/kie/kogito/services/uow/TransactionAwareUnitOfWorkExecutor.java
@@ -20,18 +20,14 @@ package org.kie.kogito.services.uow;
import java.util.function.Supplier;
-import org.kie.kogito.process.ProcessInstanceExecutionException;
import org.kie.kogito.uow.UnitOfWork;
import org.kie.kogito.uow.UnitOfWorkManager;
-public class UnitOfWorkExecutor {
+public class TransactionAwareUnitOfWorkExecutor extends UnitOfWorkExecutor {
- private UnitOfWorkExecutor() {
-
- }
-
- public static <T> T executeInUnitOfWork(UnitOfWorkManager uowManager,
Supplier<T> supplier) {
- T result = null;
+ @Override
+ public <T> T execute(UnitOfWorkManager uowManager, Supplier<T> supplier) {
+ T result;
UnitOfWork uow = uowManager.newUnitOfWork();
try {
@@ -41,18 +37,9 @@ public class UnitOfWorkExecutor {
uow.end();
return result;
- } catch (ProcessInstanceExecutionException e) {
- uow.end();
- throw e;
- } catch (Exception e) {
+ } catch (RuntimeException e) {
uow.abort();
- if (e instanceof RuntimeException) {
- throw (RuntimeException) e;
- } else {
- throw new RuntimeException(e);
- }
+ throw e;
}
-
}
-
}
diff --git
a/api/kogito-services/src/main/java/org/kie/kogito/services/uow/UnitOfWorkExecutor.java
b/api/kogito-services/src/main/java/org/kie/kogito/services/uow/UnitOfWorkExecutor.java
index 07127db117..98010c6fe1 100644
---
a/api/kogito-services/src/main/java/org/kie/kogito/services/uow/UnitOfWorkExecutor.java
+++
b/api/kogito-services/src/main/java/org/kie/kogito/services/uow/UnitOfWorkExecutor.java
@@ -20,39 +20,30 @@ package org.kie.kogito.services.uow;
import java.util.function.Supplier;
-import org.kie.kogito.process.ProcessInstanceExecutionException;
-import org.kie.kogito.uow.UnitOfWork;
import org.kie.kogito.uow.UnitOfWorkManager;
-public class UnitOfWorkExecutor {
+public abstract class UnitOfWorkExecutor {
- private UnitOfWorkExecutor() {
+ private static volatile UnitOfWorkExecutor unitOfWorkExecutor;
+ public static void set(UnitOfWorkExecutor executor) {
+ unitOfWorkExecutor = executor;
}
- public static <T> T executeInUnitOfWork(UnitOfWorkManager uowManager,
Supplier<T> supplier) {
- T result = null;
- UnitOfWork uow = uowManager.newUnitOfWork();
-
- try {
- uow.start();
-
- result = supplier.get();
- uow.end();
-
- return result;
- } catch (ProcessInstanceExecutionException e) {
- uow.end();
- throw e;
- } catch (Exception e) {
- uow.abort();
- if (e instanceof RuntimeException) {
- throw (RuntimeException) e;
- } else {
- throw new RuntimeException(e);
+ private static UnitOfWorkExecutor getExecutor() {
+ if (unitOfWorkExecutor == null) {
+ synchronized (UnitOfWorkExecutor.class) {
+ if (unitOfWorkExecutor == null) {
+ unitOfWorkExecutor = new DefaultUnitOfWorkExecutor();
+ }
}
}
+ return unitOfWorkExecutor;
+ }
+ public static <T> T executeInUnitOfWork(UnitOfWorkManager uowManager,
Supplier<T> supplier) {
+ return getExecutor().execute(uowManager, supplier);
}
+ abstract <T> T execute(UnitOfWorkManager uowManager, Supplier<T> supplier);
}
diff --git
a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/NodeInstanceImpl.java
b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/NodeInstanceImpl.java
index 6db271f963..2dc6622ab3 100755
---
a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/NodeInstanceImpl.java
+++
b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/NodeInstanceImpl.java
@@ -304,6 +304,16 @@ public abstract class NodeInstanceImpl implements
org.jbpm.workflow.instance.Nod
} catch (Exception e) {
ExceptionScopeInstance exceptionScopeInstance =
(ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE,
e);
if (exceptionScopeInstance == null) {
+ if
(!WORKFLOW_PARAM_TRANSACTIONS.get(getProcessInstance().getProcess())) {
+ logger.error("Error executing node instance '{}' (node
'{}' id: '{}') in process instance '{}' (process: '{}') in a non transactional
environment ", getStringId(), getNodeName(),
+ getNodeDefinitionId(), processInstance.getId(),
processInstance.getProcessId());
+ captureError(e);
+ } else {
+ logger.error("Error {} executing node instance '{}' (node
'{}' id: '{}') in process instance '{}' (process: '{}') in a transactional
environment (Wrapping)", e.getMessage(),
+ getStringId(), getNodeName(),
+ getNodeDefinitionId(), processInstance.getId(),
processInstance.getProcessId());
+ throw new
ProcessInstanceExecutionException(this.getProcessInstance().getId(),
this.getNodeDefinitionId(), this.getId(), e.getMessage(), e);
+ }
throw new WorkflowRuntimeException(this, getProcessInstance(),
"Unable to execute Action: " + e.getMessage(), e);
}
context.getContextData().put("Exception", e);
diff --git
a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java
b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java
index b80405bca4..313a72ce22 100644
---
a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java
+++
b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java
@@ -505,7 +505,7 @@ public class ProcessCodegen extends AbstractGenerator {
generateSourceFileProviderProducer();
- if (CodegenUtil.isTransactionEnabled(this, context()) &&
!isServerless) {
+ if (isTransactionEnabled(this, context()) && !isServerless) {
String template = "ExceptionHandlerTransaction";
TemplatedGenerator generator = TemplatedGenerator.builder()
.withTemplateBasePath("/class-templates/transaction/")
@@ -516,6 +516,17 @@ public class ProcessCodegen extends AbstractGenerator {
storeFile(MODEL_TYPE, generator.generatedFilePath(),
handler.toString());
}
+ if (isTransactionEnabled(this, context())) {
+ TemplatedGenerator generator = TemplatedGenerator.builder()
+ .withTemplateBasePath("/class-templates/transaction/")
+ .withFallbackContext(JavaKogitoBuildContext.CONTEXT_NAME)
+ .build(context(), "UnitOfWorkExecutorInitializer");
+
+ storeFile(GeneratedFileType.SOURCE,
+ generator.generatedFilePath(),
+ generator.compilationUnitOrThrow().toString());
+ }
+
if (context().hasRESTForGenerator(this)) {
for (ProcessResourceGenerator resourceGenerator : rgs) {
storeFile(REST, resourceGenerator.generatedFilePath(),
diff --git
a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/UnitOfWorkExecutorInitializerQuarkusTemplate.java
b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/UnitOfWorkExecutorInitializerQuarkusTemplate.java
new file mode 100644
index 0000000000..822226fb40
--- /dev/null
+++
b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/UnitOfWorkExecutorInitializerQuarkusTemplate.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import jakarta.annotation.PostConstruct;
+import jakarta.enterprise.context.ApplicationScoped;
+import io.quarkus.runtime.Startup;
+import org.kie.kogito.services.uow.UnitOfWorkExecutor;
+import org.kie.kogito.services.uow.TransactionAwareUnitOfWorkExecutor;
+
+@Startup
+@ApplicationScoped
+public class UnitOfWorkExecutorInitializer {
+
+ @PostConstruct
+ void init() {
+ UnitOfWorkExecutor.set(new TransactionAwareUnitOfWorkExecutor());
+ }
+}
diff --git
a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/UnitOfWorkExecutorInitializerSpringTemplate.java
b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/UnitOfWorkExecutorInitializerSpringTemplate.java
new file mode 100644
index 0000000000..02aa91fd8c
--- /dev/null
+++
b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/transaction/UnitOfWorkExecutorInitializerSpringTemplate.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import jakarta.annotation.PostConstruct;
+import org.springframework.stereotype.Component;
+import org.kie.kogito.services.uow.UnitOfWorkExecutor;
+import org.kie.kogito.services.uow.TransactionAwareUnitOfWorkExecutor;
+
+@Component
+public class UnitOfWorkExecutorInitializer {
+
+ @PostConstruct
+ void init() {
+ UnitOfWorkExecutor.set(new TransactionAwareUnitOfWorkExecutor());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]