Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fail handler to executor #1109

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ type Executor interface {
Cancel(ctx context.Context, runID ulid.ULID, r CancelRequest) error
// Resume resumes an in-progress function run from the given waitForEvent pause.
Resume(ctx context.Context, p state.Pause, r ResumeRequest) error
// Fail fails a functin with the given error.
Fail(ctx context.Context, runID ulid.ULID, err error) error

// AddLifecycleListener adds a lifecycle listener to run on hooks. This must
// always add to a list of listeners vs replace listeners.
Expand Down
42 changes: 42 additions & 0 deletions pkg/execution/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,48 @@ func (e *executor) handleAggregatePauses(ctx context.Context, evt event.TrackedE
return res, goerr
}

func (e *executor) Fail(ctx context.Context, runID ulid.ULID, with error) error {
s, err := e.sm.Load(ctx, runID)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the func argument should either be renamed from err of the ones in the function should be renamed based on the warning.

if err != nil {
return fmt.Errorf("unable to load run: %w", err)
}
md := s.Metadata()

switch md.Status {
case enums.RunStatusFailed, enums.RunStatusCompleted, enums.RunStatusOverflowed:
return ErrFunctionEnded
case enums.RunStatusCancelled:
return nil
}

if err := e.sm.SetStatus(ctx, md.Identifier, enums.RunStatusFailed); err != nil {
return fmt.Errorf("error cancelling function: %w", err)
}

msg := with.Error()
if err := e.runFinishHandler(ctx, s.Identifier(), s, state.DriverResponse{
Err: &msg,
}); err != nil {
logger.From(ctx).Error().Err(err).Msg("error running finish handler")
}

for _, e := range e.lifecycles {
go e.OnFunctionFinished(
context.WithoutCancel(ctx),
md.Identifier,
queue.Item{
Identifier: s.Identifier(),
},
state.DriverResponse{
Err: &msg,
},
s,
)
}

return nil
}

// Cancel cancels an in-progress function.
func (e *executor) Cancel(ctx context.Context, runID ulid.ULID, r execution.CancelRequest) error {
s, err := e.sm.Load(ctx, runID)
Expand Down
Loading