Repository navigation
Use Status.IsTerminal for every terminal run check - #3970
Conversation
Several call sites inferred the terminal set as status != NotStarted && !IsActive(). Use ir.Status.IsTerminal() instead so there is one definition. Follow-up from dagucloud#3676.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
yohamta0
left a comment
There was a problem hiding this comment.
Thanks for following up on this! LGTM.
Summary
Follow-up from #3676, where @yohamta0 pointed out that a few call sites still work out "the run has ended" on their own as
status != NotStarted && !IsActive()instead of usingir.Status.IsTerminal(). If a status is added toir.Statuslater, those copies andIsTerminal()would disagree. This switches them all toIsTerminal(), so there is one definition.Changes
internal/service/coordinator: dropisTerminalRunStatusand callStatus.IsTerminal()at its callers (distributed_attempts.go,handler.go,remote_attempt.go). Also replace the five inline!IsActive() && != NotStartedchecks inhandler.go.internal/cmd/retry.go:retrySourceMayStillBeFinalizingusesIsTerminal().internal/runtime/agent/agent.go:pushStatuspicks the terminal push timeout withIsTerminal().internal/service/worker/coordreport/status_pusher.go: the final-delivery retry check usesIsTerminal().internal/service/coordinator/subflow/runner.goandinternal/service/frontend/api/v1/service_dags.go(runEnded): same.No user-visible change.
Core change
For every defined status the old expression and
IsTerminal()give the same answer: both are true for Failed, Aborted, Succeeded, PartiallySucceeded and Rejected, and false for NotStarted, Running, Queued and Waiting. The only difference is a value outside the enum: the old expression treated it as ended,IsTerminal()treats it as not ended (itsdefaultbranch).Testing
No new test.
TestStatus_IsTerminalininternal/ir/status_test.goalready pins the set, and the call sites keep their current tests.go build ./...go veton the touched packages.internal/runtime/agentreports alostcancelwarning atagent.go:1224, which is on main too and not touched here.go test -count=1 ./internal/ir/ ./internal/cmd/ ./internal/runtime/agent/ ./internal/service/coordinator/... ./internal/service/frontend/api/v1/ ./internal/service/worker/coordreport/: all pass.golangci-lint run --new-from-rev=upstream/mainon the touched packages: 0 issues.Not run:
make test(race),make check, conformance, Windows.Environment: main @ 395de48, go1.27.4, darwin/arm64.
Performance
No performance risk: each change swaps one in-memory status comparison for another, on the same paths.
Out of scope
runEnded(string)ininternal/service/scheduler/restart_scanner.golists the same five statuses, but it matches event status strings, so switching it means parsing the string first. Left as is.handler.go:2268keepslatestStatus.Status != ir.NotStarted && !...IsTerminal(). ThatNotStartedcheck isn't redundant (NotStarted isn't terminal), and the condition reads as "is active", so I didn't rewrite it.Summary by cubic
Replaces every hand-rolled terminal-run check (
status != ir.NotStarted && !status.IsActive()) with the centralizedir.Status.IsTerminal()so there is a single definition of a terminal status.Refactors
isTerminalRunStatushelper ininternal/service/coordinatorand callsStatus.IsTerminal()at its call sites.handler.go,retry.go,agent.go,coordreport/status_pusher.go,subflow/runner.go, andservice_dags.goforIsTerminal().Written for commit 9b5d968. Summary will update on new commits.
Summary by CodeRabbit