handler

package
v0.0.0-...-9b6032d Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Overview

Package handler implements handlers that handles run events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLUpdater

type CLUpdater interface {
	ScheduleBatch(ctx context.Context, luciProject string, cls []*changelist.CL, requester changelist.UpdateCLTask_Requester) 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, []string) (*Result, error)

	// OnCLsUpdated decides whether to cancel a Run based on changes to the CLs.
	OnCLsUpdated(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)

	// 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)

	// OnCLsSubmitted records provided CLs have been submitted.
	OnCLsSubmitted(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)

	// OnLongOpCompleted processes results of the completed long operation.
	OnLongOpCompleted(ctx context.Context, rs *state.RunState, result *eventpb.LongOpCompleted) (*Result, error)

	// OnTryjobsUpdated decides the next step for the given tryjobs and the run.
	OnTryjobsUpdated(context.Context, *state.RunState, common.TryjobIDs) (*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)

	// OnParentRunCompleted checks decides how to handle the run based on its completed parent run.
	OnParentRunCompleted(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
	TN          TryjobNotifier
	QM          QM
	GFactory    gerrit.Factory
	CLUpdater   CLUpdater
	CLMutator   *changelist.Mutator
	BQExporter  *bq.Exporter
	RdbNotifier *rdb.Notifier
	TreeClient  tree.Client
	Publisher   *pubsub.Publisher
	Env         *common.Env
}

Impl is a prod implementation of Handler interface.

func (*Impl) Cancel

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

Cancel implements Handler interface.

func (*Impl) OnCLsSubmitted

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

OnCLsSubmitted implements Handler interface.

func (*Impl) OnCLsUpdated

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

OnCLsUpdated implements Handler interface.

func (*Impl) OnLongOpCompleted

func (impl *Impl) OnLongOpCompleted(ctx context.Context, rs *state.RunState, result *eventpb.LongOpCompleted) (*Result, error)

OnLongOpCompleted implements Handler interface.

func (*Impl) OnParentRunCompleted

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

OnParentRunCompleted 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) OnTryjobsUpdated

func (impl *Impl) OnTryjobsUpdated(ctx context.Context, rs *state.RunState, tryjobs common.TryjobIDs) (*Result, error)

OnTryjobsUpdated 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 *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, status run.Status) error
	NotifyCLsUpdated(ctx context.Context, luciProject string, cls *changelist.CLUpdatedEvents) error
}

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

type QM

type QM interface {
	DebitRunQuota(ctx context.Context, r *run.Run) (*quotapb.OpResult, *cfgpb.UserLimit, error)
}

QM manages run and tryjob quotas.

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
	NotifyCLsSubmitted(ctx context.Context, runID common.RunID, clids common.CLIDs) error
	NotifySubmissionCompleted(ctx context.Context, runID common.RunID, sc *eventpb.SubmissionCompleted, invokeRM bool) error
	Start(ctx context.Context, runID common.RunID) error
	NotifyParentRunCompleted(ctx context.Context, runID common.RunID) 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.

type TryjobNotifier

type TryjobNotifier interface {
	ScheduleUpdate(ctx context.Context, id common.TryjobID, eid tryjob.ExternalID) error
}

TryjobNotifier encapsulates interaction with Tryjob components by the Run events handler.

Jump to

Keyboard shortcuts

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