FrankYang0529 commented on code in PR #75538:
URL: https://github.com/apache/airflow/pull/75538#discussion_r4585825638
##########
java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/execution/Task.kt:
##########
@@ -142,15 +141,22 @@ internal object TaskRunner {
return TaskResult.failure(request.tiContext.shouldRetry)
}
return try {
- val context = Context.from(request, taskDef)
+ val context = Context.from(request, taskDef, cancellation)
+ if (instance is StoppableTask) cancellation?.hold(instance, context)
val decider = taskDef.decider
if (decider == null) instance.execute(context, client) else
decide(decider, taskDef, instance, context, client)
TaskResult.success()
- } catch (e: CancellationException) {
- throw e // Let coroutine cancellation propagate so the task coroutine
unwinds.
+ } catch (e: CannotCatchStopSignalsException) {
+ logger.error("Cannot start the task", mapOf("ti" to request.ti, "error"
to e))
+ // A retry usually runs with the same JVM options and runtime image, so
it would fail the same way.
+ TaskResult.failure(shouldRetry = false)
} catch (e: Throwable) {
+ // Throwable includes CancellationException, which a task gets from a
future that onKill cancelled.
+ // The serve coroutine's own cancellation cannot reach this blocking
call, so the exception comes
+ // from the task.
logger.error("Error executing task", mapOf("ti" to request.ti, "error"
to e, "trace" to e.stackTraceToString()))
- TaskResult.failure(request.tiContext.shouldRetry)
+ // A task that cannot see a stop request would fail the same way on
every retry.
+ TaskResult.failure(request.tiContext.shouldRetry && e !is
TaskCannotSeeStopRequestException)
Review Comment:
Both exceptions now extend a new internal `NonRetryableException`. Thanks
for the suggestion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]