handler

package
v0.0.0-...-51f9457 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package handler implements handlers that handles run events.

Index

Constants

This section is empty.

Variables

View Source
var ErrTransientSubmissionFailure = errors.New("submission failed transiently", transient.Tag)

ErrTransientSubmissionFailure indicates that the submission has failed transiently and the same task should be retried.

Functions

This section is empty.

Types

type CLUpdater

type CLUpdater interface {
	ScheduleBatch(ctx context.Context, luciProject string, cls []*changelist.CL) error
}

CLUpdater encapsulates interaction with CL Updater by the Run events handler.

type Handler

type Handler interface {
	// Start starts a Run.
	Start(context.Context, *state.RunState) (*Result, error)

	// Cancel cancels a Run.
	Cancel(context.Context, *state.RunState) (*Result, error)

	// OnCLUpdated decides whether to cancel a Run based on changes to the CLs.
	OnCLUpdated(context.Context, *state.RunState, common.CLIDs) (*Result, error)

	// UpdateConfig updates Run's config if possible.
	// If Run is no longer viable, cancels the Run.
	UpdateConfig(context.Context, *state.RunState, string) (*Result, error)

	// OnCQDVerificationCompleted finalizes the Run according to the verified
	// Run reported by CQDaemon.
	OnCQDVerificationCompleted(context.Context, *state.RunState) (*Result, error)

	// OnReadyForSubmission acquires a slot in Submit Queue and makes sure this
	// Run is not currently being submitted by another RM task. If all succeeded,
	// returns a PostProcessFn for submission.
	OnReadyForSubmission(context.Context, *state.RunState) (*Result, error)

	// OnCLSubmitted records provided CLs have been submitted.
	OnCLSubmitted(context.Context, *state.RunState, common.CLIDs) (*Result, error)

	// OnSubmissionCompleted acts on the submission result.
	//
	// If submission succeeds, mark run as `SUCCEEDED`. Otherwise, decides whether
	// to retry submission or fail the run depending on the submission result.
	OnSubmissionCompleted(ctx context.Context, rs *state.RunState, sc *eventpb.SubmissionCompleted) (*Result, error)

	// TryResumeSubmission resumes not-yet-expired submission if the current task
	// is a retry of the submission task.
	//
	// Fail the Run if the submission deadline has been exceeded.
	TryResumeSubmission(context.Context, *state.RunState) (*Result, error)

	// Poke checks current Run state and takes actions to progress the Run.
	Poke(context.Context, *state.RunState) (*Result, error)
}

Handler is an interface that handles events that RunManager receives.

type Impl

type Impl struct {
	PM         PM
	RM         RM
	GFactory   gerrit.ClientFactory
	CLUpdater  CLUpdater
	BQExporter *bq.Exporter
	TreeClient tree.Client
}

Impl is a prod implementation of Handler interface.

func (*Impl) Cancel

func (impl *Impl) Cancel(ctx context.Context, rs *state.RunState) (*Result, error)

Cancel implements Handler interface.

func (*Impl) OnCLSubmitted

func (*Impl) OnCLSubmitted(ctx context.Context, rs *state.RunState, clids common.CLIDs) (*Result, error)

OnCLSubmitted implements Handler interface.

func (*Impl) OnCLUpdated

func (impl *Impl) OnCLUpdated(ctx context.Context, rs *state.RunState, clids common.CLIDs) (*Result, error)

OnCLUpdated implements Handler interface.

func (*Impl) OnCQDVerificationCompleted

func (impl *Impl) OnCQDVerificationCompleted(ctx context.Context, rs *state.RunState) (*Result, error)

OnCQDVerificationCompleted implements Handler interface.

func (*Impl) OnReadyForSubmission

func (impl *Impl) OnReadyForSubmission(ctx context.Context, rs *state.RunState) (*Result, error)

OnReadyForSubmission implements Handler interface.

func (*Impl) OnSubmissionCompleted

func (impl *Impl) OnSubmissionCompleted(ctx context.Context, rs *state.RunState, sc *eventpb.SubmissionCompleted) (*Result, error)

OnSubmissionCompleted implements Handler interface.

func (*Impl) Poke

func (impl *Impl) Poke(ctx context.Context, rs *state.RunState) (*Result, error)

Poke implements Handler interface.

func (*Impl) Start

func (*Impl) Start(ctx context.Context, rs *state.RunState) (*Result, error)

Start implements Handler interface.

func (*Impl) TryResumeSubmission

func (impl *Impl) TryResumeSubmission(ctx context.Context, rs *state.RunState) (*Result, error)

TryResumeSubmission implements Handler interface.

func (*Impl) UpdateConfig

func (impl *Impl) UpdateConfig(ctx context.Context, rs *state.RunState, hash string) (*Result, error)

UpdateConfig implements Handler interface.

type PM

type PM interface {
	NotifyRunFinished(ctx context.Context, runID common.RunID) error
	NotifyCLsUpdated(ctx context.Context, luciProject string, cls []*changelist.CL) error
}

PM encapsulates interaction with Project Manager by the Run events handler.

type RM

type RM interface {
	Invoke(ctx context.Context, runID common.RunID, eta time.Time) error
	PokeAfter(ctx context.Context, runID common.RunID, after time.Duration) error
	NotifyReadyForSubmission(ctx context.Context, runID common.RunID, eta time.Time) error
	NotifyCLSubmitted(ctx context.Context, runID common.RunID, clid common.CLID) error
	NotifySubmissionCompleted(ctx context.Context, runID common.RunID, sc *eventpb.SubmissionCompleted, invokeRM bool) error
	// TODO(crbug/1141880): Remove this API after migration. See `run.CancelAt`.
	CancelAt(ctx context.Context, runID common.RunID, eta time.Time) error
}

RM encapsulates interaction with Run Manager by the Run events handler.

type Result

type Result struct {
	// State is the new RunState after handling the events.
	State *state.RunState
	// SideEffectFn is called in a transaction to atomically transition the
	// RunState to the new state and perform side effect.
	SideEffectFn eventbox.SideEffectFn
	// PreserveEvents, if true, instructs RunManager not to consume the events
	// during state transition.
	PreserveEvents bool
	// PostProcessFn is executed by the eventbox user after event processing
	// completes.
	PostProcessFn eventbox.PostProcessFn
}

Result is the result of handling the events.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL