@@ -16,6 +16,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
1616import org.springframework.context.annotation.Lazy
1717import org.springframework.transaction.support.TransactionTemplate
1818import java.lang.reflect.Method
19+ import java.time.Duration
1920import java.util.concurrent.ExecutionException
2021
2122private val logger = KotlinLogging .logger {}
@@ -218,17 +219,14 @@ class ProcessEngineStarterRegistrar(
218219 }
219220 } else {
220221 try {
221- val retryCount = if (cause is FailJobException ) cause.retryCount
222- else taskInformation.getMetaValueAsInt(TaskInformation .RETRIES )?.apply { this - 1 }
223- val retryBackoff = if (cause is FailJobException ) cause.retryBackoff
224- else null
222+ var retry = calculateRetry(taskInformation = taskInformation, cause = cause)
225223 taskCompletionApi.failTask(
226224 FailTaskCmd (
227225 taskId = taskInformation.taskId,
228226 reason = cause.message ? : " Exception during execution of external task worker" ,
229227 errorDetails = cause.stackTraceToString(),
230- retryCount = retryCount,
231- retryBackoff = retryBackoff
228+ retryCount = retry. retryCount,
229+ retryBackoff = retry. retryBackoff
232230 )
233231 ).get()
234232 processEngineWorkerMetrics.taskFailed(topic)
@@ -240,7 +238,24 @@ class ProcessEngineStarterRegistrar(
240238 }
241239 }
242240
243- private fun completeBeforeCommit (complete : Completion ): Boolean =
241+ internal fun calculateRetry (taskInformation : TaskInformation , cause : Throwable ): FailureRetry {
242+ val retryCount = if (cause is FailJobException ) {
243+ cause.retryCount
244+ } else {
245+ taskInformation.getMetaValueAsInt(TaskInformation .RETRIES )?.let { it - 1 }
246+ }
247+ val retryBackoff = if (cause is FailJobException ) {
248+ cause.retryBackoff
249+ } else {
250+ null
251+ }
252+ return FailureRetry (
253+ retryCount = retryCount,
254+ retryBackoff = retryBackoff
255+ )
256+ }
257+
258+ internal fun completeBeforeCommit (complete : Completion ): Boolean =
244259 if (complete == DEFAULT ) {
245260 processEngineWorkerProperties.completeTasksBeforeCommit
246261 } else {
@@ -251,4 +266,13 @@ class ProcessEngineStarterRegistrar(
251266 * Task handler as a function.
252267 */
253268 fun interface TaskHandlerWithResult : (TaskInformation , Map <String , Any >) -> Any?
269+
270+ /* *
271+ * Failure retry information.
272+ */
273+ data class FailureRetry (
274+ val retryCount : Int? ,
275+ val retryBackoff : Duration ?
276+ )
277+
254278}
0 commit comments