ChickenBenny commented on code in PR #77489:
URL: https://github.com/apache/airflow/pull/77489#discussion_r4741025957
##########
go-sdk/pkg/execution/execution_timeout.go:
##########
@@ -19,17 +19,32 @@ package execution
import (
"context"
+ "errors"
"fmt"
+ "log/slog"
+ "math"
+ "time"
"github.com/apache/airflow/go-sdk/pkg/execution/genmodels"
+ "github.com/apache/airflow/go-sdk/sdk"
)
-// resolveExecutionTimeout returns the task's execution_timeout in seconds
from ti_context, or nil
-// when the task has no timeout. The coordinator has already filled in the
worker's default.
-// As in the Python task runner, zero means no timeout and a negative value
has already elapsed.
-func resolveExecutionTimeout(fromContext any) (*float64, error) {
+// executionTimeout is a task's execution_timeout. Call start before run.
Review Comment:
Folded in 03444ef8e6: `Run` sends `SetExecutionTimeout` first, and if that
fails it returns the
error without running the task. After 06f13017c2 it's sent right before the
task function (after
the args are resolved), same as the Python task runner.
##########
go-sdk/pkg/execution/execution_timeout.go:
##########
@@ -39,17 +54,91 @@ func resolveExecutionTimeout(fromContext any) (*float64,
error) {
fromContext,
)
case seconds == 0:
- return nil, nil
+ return disabledExecutionTimeout{}, nil
case seconds < 0:
return nil, fmt.Errorf("execution_timeout of %g seconds has
already elapsed", seconds)
}
- return &seconds, nil
+ return enabledExecutionTimeout{seconds: seconds}, nil
+}
+
+type disabledExecutionTimeout struct{}
+
+func (disabledExecutionTimeout) start(context.Context, *CoordinatorClient)
error {
+ return nil
}
-// setExecutionTimeout tells the supervisor the task's execution_timeout and
restarts its clock from
-// now. The runtime does not stop the task itself: killed_task_cleanup_time
after the timeout, the
-// supervisor sends SIGTERM, which cancels the task's ctx.
-func (c *CoordinatorClient) setExecutionTimeout(ctx context.Context, seconds
float64) error {
- _, err := c.comm.Communicate(ctx,
genmodels.SetExecutionTimeout{TimeoutSeconds: seconds})
+func (disabledExecutionTimeout) run(
+ stop context.Context,
+ _ bool,
+ _ *slog.Logger,
+ run func(ctx context.Context) any,
+) any {
+ return run(stop)
+}
+
+type enabledExecutionTimeout struct {
+ seconds float64
+}
+
+// start arms the supervisor, which sends SIGTERM killed_task_cleanup_time
after the timeout.
+func (t enabledExecutionTimeout) start(ctx context.Context, client
*CoordinatorClient) error {
+ _, err := client.comm.Communicate(ctx,
genmodels.SetExecutionTimeout{TimeoutSeconds: t.seconds})
return err
}
+
+// run cancels the task's ctx with sdk.TaskTimeout at the timeout, then waits
until the task
+// returns or the supervisor's SIGTERM cancels stop. The task fails with the
timeout either way.
+func (t enabledExecutionTimeout) run(
+ stop context.Context,
+ shouldRetry bool,
+ logger *slog.Logger,
+ run func(ctx context.Context) any,
Review Comment:
Renamed it to `call`.
--
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]