samples

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 14 Imported by: 0

README

Samples

Start with quickstart. make run executes it in the development container, prints result 42 and shuts down its worker and backend. It needs no external database service.

For the smallest client/worker example without activities, use make run-greeting. Both programs appear in full in the root README, and tests keep those copies synchronized with executable source.

Reading a sample

Each entry point explains its command, backend requirements, expected outcome and whether it exits or waits for Ctrl+C. Feature comments explain the behavior being demonstrated, such as replay-safe concurrency, queue routing or carrying state across executions. Follow the client submission, worker registration and workflow definition in that order. Activities use ordinary context.Context; workflow functions use workflow.Context and replay-safe APIs.

worker.Start launches background pollers and returns. A client submits serialized inputs to the backend, not directly to a worker. An accepted submission is not a completed workflow; await its typed result when completion matters. Stop polling and drain workers before closing storage. The introductory programs demonstrate that full lifecycle, including cleanup after errors.

Feature map

Topic Samples
Basic execution and typed arguments simple, complex parameters
Registration names workflows, activities
Concurrency workflow goroutines, error groups
Child workflows and execution rollover subworkflows, continue as new
External input and waiting signals, child signals, timers
Failure handling errors, retries, cancellation
Queues and separate processes queues, split workers, scaling
Serialization and context converter, context propagation
Observability tracing, web diagnostics, workflow information
Application composition orchestrator

Running other demonstrations

Inspect each sample's entry point before running it. Some wait for an interrupt instead of exiting after the first result. Some start a loopback diagnostics server. Split-worker demonstrations need their producer and consumer processes running together.

The legacy shared helper in runner.go defaults to local Redis and contains development connection settings. Its recreation mode calls Redis FlushAll, which deletes data across databases on that Redis server. Never run those demonstrations against shared or production storage. Prefer an isolated in-memory or file-backed backend where the sample supports it.

From make shell, run a single-process feature demo with its documented command, for example go run ./samples/concurrent -backend memory. Split-process samples use -backend sqlite in both shells with the same working directory. In-memory storage cannot connect separate processes. Multi-host workers need a shared PostgreSQL, MySQL or Redis backend instead of the demo's local file.

The tracing sample also needs an OTLP/HTTP collector on port 4318 for export. Web diagnostics deliberately use slow activities and currently report a client timeout before those activities finish. The retries demo uses process-local counters to simulate failures in one instance; those counters are not a durable or concurrent application design.

Use make shell to enter the development toolchain for manual demonstrations. Production applications should construct their own backend and configuration rather than import the sample helper. See architecture, workflow behavior and backend operations.

Documentation

Overview

Package samples provides development-only backend wiring for the feature demos. Use -backend memory for isolated single-process examples, or -backend sqlite for processes sharing a local file. The default Redis recreation path flushes ALL databases on localhost:6379. Never use it with shared or production storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBackend

func GetBackend(name string, recreate bool, opt ...backend.BackendOption) backend.Backend

GetBackend parses demo CLI flags and opens storage using fixed local settings. It is not application configuration. In Redis mode it also starts diagnostics on loopback port 3000; demos with their own diagnostics should use another backend.

Types

This section is empty.

Directories

Path Synopsis
Run from make shell with: go run ./samples/activity-registration -backend memory.
Run from make shell with: go run ./samples/activity-registration -backend memory.
Run from make shell with: go run ./samples/cancellation -backend memory.
Run from make shell with: go run ./samples/cancellation -backend memory.
Run from make shell with: go run ./samples/complex-parameters -backend memory.
Run from make shell with: go run ./samples/complex-parameters -backend memory.
Run from make shell with: go run ./samples/concurrent -backend memory.
Run from make shell with: go run ./samples/concurrent -backend memory.
Run from make shell with: go run ./samples/concurrent-errgroup -backend memory.
Run from make shell with: go run ./samples/concurrent-errgroup -backend memory.
Run from make shell with: go run ./samples/context-propagation -backend memory.
Run from make shell with: go run ./samples/context-propagation -backend memory.
Run from make shell with: go run ./samples/continue-as-new -backend memory.
Run from make shell with: go run ./samples/continue-as-new -backend memory.
Run from make shell with: go run ./samples/converter -backend memory.
Run from make shell with: go run ./samples/converter -backend memory.
Run from make shell with: go run ./samples/errors -backend memory.
Run from make shell with: go run ./samples/errors -backend memory.
This example shows the smallest client/worker connection without activities.
This example shows the smallest client/worker connection without activities.
Run from make shell with: go run ./samples/orchestrator -backend memory.
Run from make shell with: go run ./samples/orchestrator -backend memory.
Run from make shell with: go run ./samples/queues -backend memory.
Run from make shell with: go run ./samples/queues -backend memory.
This example runs a client and worker in one process against a SQLite file.
This example runs a client and worker in one process against a SQLite file.
Run from make shell with: go run ./samples/retries -backend memory.
Run from make shell with: go run ./samples/retries -backend memory.
Each instance runs two activities sequentially.
Each instance runs two activities sequentially.
starter command
Producer for the scaling demonstration.
Producer for the scaling demonstration.
worker command
Consumer for the scaling demonstration.
Consumer for the scaling demonstration.
Run from make shell with: go run ./samples/signal -backend memory.
Run from make shell with: go run ./samples/signal -backend memory.
Run from make shell with: go run ./samples/signal-subworkflow -backend memory.
Run from make shell with: go run ./samples/signal-subworkflow -backend memory.
Run from make shell with: go run ./samples/simple -backend memory.
Run from make shell with: go run ./samples/simple -backend memory.
Package simple_split_worker contains definitions shared by the producer and consumer binaries.
Package simple_split_worker contains definitions shared by the producer and consumer binaries.
starter command
Producer process.
Producer process.
worker command
Consumer process.
Consumer process.
Run from make shell with: go run ./samples/subworkflow -backend memory.
Run from make shell with: go run ./samples/subworkflow -backend memory.
Run from make shell with: go run ./samples/timer -backend memory.
Run from make shell with: go run ./samples/timer -backend memory.
Run from make shell with: go run ./samples/tracing -backend memory.
Run from make shell with: go run ./samples/tracing -backend memory.
Run from make shell with: go run ./samples/web -backend memory.
Run from make shell with: go run ./samples/web -backend memory.
Run from make shell with: go run ./samples/workflow-info.
Run from make shell with: go run ./samples/workflow-info.
Run from make shell with: go run ./samples/workflow-registration -backend memory.
Run from make shell with: go run ./samples/workflow-registration -backend memory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL