mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-03-17 18:22:39 -05:00
* feat: initial ruby sdk * fix: run listener * fix: scope * feat: rest feature clients * fix: bugs * fix: concurrent register * fix: tests and ergonomics * docs: all of them * chore: lint * feat: add RBS * feat: add GitHub Actions workflow for Ruby SDK with linting, testing, and publishing steps * chore: lint * refactor: simplify load path setup for Hatchet REST client and remove symlink creation * fix: cert path * fix: test * fix: blocking * fix: ensure Hatchet client is only initialized once across examples * fix: tests * remove: unused example * fix: bubble up errors * test: skip flaky for now * remove: lifespans * fix: durable context bugs * fix: bulk replay * fix: tests * cleanup: generate tooling * fix: integration test * chore: lint * release: 0.1.0 * chore: remove python comments * refactor: remove OpenTelemetry configuration and related unused options * fix: default no healthcheck * chore: lockfile * feat: register as ruby * chore: lint * chore: update py/ts apis to include ruby * chore: docs pass * chore: lint * chore: generate * chore: cleanup * chore: generate examples * tests: add e2e tests * tests: cache examples dependencies * fix: namespace * fix: namespace * fix: namespaces * chore:lint * fix: improve cancellation workflow polling logic and add error handling * revert: py/ts versions
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package shared
|
|
|
|
import (
|
|
"time"
|
|
|
|
hatchet "github.com/hatchet-dev/hatchet/sdks/go"
|
|
)
|
|
|
|
type StreamTaskInput struct{}
|
|
|
|
type StreamTaskOutput struct {
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// > Streaming
|
|
const annaKarenina = `
|
|
Happy families are all alike; every unhappy family is unhappy in its own way.
|
|
|
|
Everything was in confusion in the Oblonskys' house. The wife had discovered that the husband was carrying on an intrigue with a French girl, who had been a governess in their family, and she had announced to her husband that she could not go on living in the same house with him.
|
|
`
|
|
|
|
func createChunks(content string, n int) []string {
|
|
var chunks []string
|
|
for i := 0; i < len(content); i += n {
|
|
end := i + n
|
|
if end > len(content) {
|
|
end = len(content)
|
|
}
|
|
chunks = append(chunks, content[i:end])
|
|
}
|
|
return chunks
|
|
}
|
|
|
|
func StreamTask(ctx hatchet.Context, input StreamTaskInput) (*StreamTaskOutput, error) {
|
|
time.Sleep(2 * time.Second)
|
|
|
|
chunks := createChunks(annaKarenina, 10)
|
|
|
|
for _, chunk := range chunks {
|
|
ctx.PutStream(chunk)
|
|
time.Sleep(200 * time.Millisecond)
|
|
}
|
|
|
|
return &StreamTaskOutput{
|
|
Message: "Streaming completed",
|
|
}, nil
|
|
}
|
|
|
|
func StreamingWorkflow(client *hatchet.Client) *hatchet.StandaloneTask {
|
|
return client.NewStandaloneTask("stream-example", StreamTask)
|
|
}
|