Documentation
¶
Overview ¶
Package runcontrol is what a caller that does not execute a managed-script run does to it: wait for it to finish, and ask it to stop (#1845, #1847).
Both run_script and the portal's run route hold a request open for a run a worker executes somewhere else, and both let the person who can read a run cancel it. The run store answers a cancel with the status the run had when the request arrived; this package is the one reading of what that status means, so the two surfaces cannot word it differently.
Index ¶
Constants ¶
const MaxWaitSeconds = 300
MaxWaitSeconds caps how long a request holds open for a run to finish, on every surface that offers to wait. Past it the caller gets the run id and follows the run, rather than a request held open for the length of a run.
const PollEvery = 300 * time.Millisecond
PollEvery is how often a wait re-reads the run row. The worker is woken the moment a run is enqueued, so this is how long a caller waits AFTER the run finishes, not before it starts; holding a LISTEN connection per waiting request would buy at most this interval and cost a connection each.
Variables ¶
This section is empty.
Functions ¶
func AwaitRun ¶
func AwaitRun(ctx context.Context, runs RunReader, run *script.Run, budget, pollEvery time.Duration) (*script.Run, bool, error)
AwaitRun re-reads a run every pollEvery until it is terminal or budget runs out, and returns the latest read along with whether it finished. A read that fails, or a context that ends, stops the wait with the last run seen: the run is executing elsewhere, and neither says anything about it. A failed read is returned for the caller to log; it is not the run's failure. It is the one wait run_script and the portal's run route both use (#1845).
func CancelMessage ¶
CancelMessage states what a cancel did, from the status the run had when it arrived, in the words a person reads.
Types ¶
type CancelOutcome ¶
type CancelOutcome string
CancelOutcome is what a cancel request did, as the surfaces that take one report it (#1847).
const ( // CanceledQueued: the run was pending and is now canceled; no worker // will claim it. CanceledQueued CancelOutcome = "canceled" // CancelRequested: the run is executing, and its worker stops it at its // next report, within seconds. CancelRequested CancelOutcome = "requested" // CancelAlreadyFinished: the run had already ended, and nothing changed. CancelAlreadyFinished CancelOutcome = "already_finished" )
Cancel outcomes.
func OutcomeOf ¶
func OutcomeOf(prior string) CancelOutcome
OutcomeOf reads what a cancel did from the status the run had when it arrived, which is what the run store answers.