mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-30 21:29:44 -06:00
* api changes * doc changes * move docs * generated * generate * pkg * backmerge main * revert to main * revert main * race? * remove go tests
56 lines
1.2 KiB
Go
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
|
|
}
|
|
|
|
// !!
|