mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-04 07:39:43 -06:00
* add Go SDK streaming support * make docs changes for go sdk streaming * fix git lfs warning * streaming go example * fix lint * fix auto generated snip * revert poetry lock changes * some cleanup
42 lines
804 B
Go
42 lines
804 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/hatchet-dev/hatchet/examples/go/streaming/shared"
|
|
v1 "github.com/hatchet-dev/hatchet/pkg/v1"
|
|
)
|
|
|
|
// > Consume
|
|
func main() {
|
|
hatchet, err := v1.NewHatchetClient()
|
|
if err != nil {
|
|
log.Fatalf("Failed to create Hatchet client: %v", err)
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
streamingWorkflow := shared.StreamingWorkflow(hatchet)
|
|
|
|
workflowRun, err := streamingWorkflow.RunNoWait(ctx, shared.StreamTaskInput{})
|
|
if err != nil {
|
|
log.Fatalf("Failed to run workflow: %v", err)
|
|
}
|
|
|
|
id := workflowRun.RunId()
|
|
stream, err := hatchet.Runs().SubscribeToStream(ctx, id)
|
|
if err != nil {
|
|
log.Fatalf("Failed to subscribe to stream: %v", err)
|
|
}
|
|
|
|
for content := range stream {
|
|
fmt.Print(content)
|
|
}
|
|
|
|
fmt.Println("\nStreaming completed!")
|
|
}
|
|
|
|
// !!
|