mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-04-27 13:09:35 -05:00
8e80faf2d6
* api changes * doc changes * move docs * generated * generate * pkg * backmerge main * revert to main * revert main * race? * remove go tests
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
v1_workflows "github.com/hatchet-dev/hatchet/examples/go/workflows"
|
|
"github.com/hatchet-dev/hatchet/pkg/client"
|
|
v1 "github.com/hatchet-dev/hatchet/pkg/v1"
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
func priority() {
|
|
err := godotenv.Load()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
hatchet, err := v1.NewHatchetClient()
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
priorityWorkflow := v1_workflows.Priority(hatchet)
|
|
|
|
// > Running a Task with Priority
|
|
priority := int32(3)
|
|
|
|
runId, err := priorityWorkflow.RunNoWait(ctx, v1_workflows.PriorityInput{
|
|
UserId: "1234",
|
|
}, client.WithPriority(priority))
|
|
// !!
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fmt.Println(runId)
|
|
|
|
// > Schedule and cron
|
|
schedulePriority := int32(3)
|
|
runAt := time.Now().Add(time.Minute)
|
|
|
|
scheduledRunId, _ := priorityWorkflow.Schedule(ctx, runAt, v1_workflows.PriorityInput{
|
|
UserId: "1234",
|
|
}, client.WithPriority(schedulePriority))
|
|
|
|
cronId, _ := priorityWorkflow.Cron(ctx, "my-cron", "* * * * *", v1_workflows.PriorityInput{
|
|
UserId: "1234",
|
|
}, client.WithPriority(schedulePriority))
|
|
// !!
|
|
|
|
fmt.Println(scheduledRunId)
|
|
fmt.Println(cronId)
|
|
|
|
// !!
|
|
}
|