Package handler implements handlers that handles run events.



    This section is empty.


    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.


      This section is empty.


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

        Handler is an interface that handles events that RunManager receives.

        type Impl

        type Impl struct {
        	PM PM
        	RM RM

          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) OnSubmissionCompleted(ctx context.Context, rs *state.RunState, sc *eventpb.SubmissionCompleted) (*Result, error)

                      OnSubmissionCompleted implements Handler interface.

                      func (*Impl) Start

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

                        Start implements Handler interface.

                        type PM

                        type PM interface {
                        	NotifyRunFinished(ctx context.Context, runID common.RunID) 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
                          	PokeAt(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

                            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.