Files
hatchet/pkg/examples/workflows/priority.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 (
"time"
"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 PriorityInput struct {
UserId string `json:"userId"`
}
type PriorityOutput struct {
TransformedMessage string `json:"TransformedMessage"`
}
type Result struct {
Step PriorityOutput
}
func Priority(hatchet v1.HatchetClient) workflow.WorkflowDeclaration[PriorityInput, Result] {
// Create a standalone task that transforms a message
// > Default priority
defaultPriority := int32(1)
workflow := factory.NewWorkflow[PriorityInput, Result](
create.WorkflowCreateOpts[PriorityInput]{
Name: "priority",
DefaultPriority: &defaultPriority,
},
hatchet,
)
// !!
// > Defining a Task
workflow.Task(
create.WorkflowTask[PriorityInput, Result]{
Name: "step",
}, func(ctx worker.HatchetContext, input PriorityInput) (interface{}, error) {
time.Sleep(time.Second * 5)
return &PriorityOutput{
TransformedMessage: input.UserId,
}, nil
},
)
// !!
return workflow
}
// !!