Files
hatchet/pkg/examples/workflows/on-failure.go
Gabe Ruttner 8e80faf2d6 Fe overhaul docs (#1640)
* api changes

* doc changes

* move docs

* generated

* generate

* pkg

* backmerge main

* revert to main

* revert main

* race?

* remove go tests
2025-04-30 14:10:09 -07:00

56 lines
1.2 KiB
Go

package v1_workflows
import (
"errors"
"github.com/hatchet-dev/hatchet/pkg/client/create"
v1 "github.com/hatchet-dev/hatchet/pkg/v1"
"github.com/hatchet-dev/hatchet/pkg/v1/factory"
"github.com/hatchet-dev/hatchet/pkg/v1/workflow"
"github.com/hatchet-dev/hatchet/pkg/worker"
)
type AlwaysFailsOutput struct {
TransformedMessage string
}
type OnFailureOutput struct {
FailureRan bool
}
type OnFailureSuccessResult struct {
AlwaysFails AlwaysFailsOutput
}
func OnFailure(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[any, OnFailureSuccessResult] {
simple := factory.NewWorkflow[any, OnFailureSuccessResult](
create.WorkflowCreateOpts[any]{
Name: "on-failure",
},
hatchet,
)
simple.Task(
create.WorkflowTask[any, OnFailureSuccessResult]{
Name: "AlwaysFails",
},
func(ctx worker.HatchetContext, _ any) (interface{}, error) {
return &AlwaysFailsOutput{
TransformedMessage: "always fails",
}, errors.New("always fails")
},
)
simple.OnFailure(
create.WorkflowOnFailureTask[any, OnFailureSuccessResult]{},
func(ctx worker.HatchetContext, _ any) (interface{}, error) {
return &OnFailureOutput{
FailureRan: true,
}, nil
},
)
return simple
}