Skip to content

temporal-sa/temporal-training-exercise-go

Repository files navigation

Temporal Training Exercise - Go Solution

Complete Go implementation for progressive Temporal training exercises.

Prerequisites

  • Go 1.21+
  • Temporal CLI

Installing Temporal CLI

macOS (Homebrew):

brew install temporal

Linux:

curl -sSf https://temporal.download/cli.sh | sh

Windows:

scoop install temporal-cli

Or download directly: Visit https://github.com/temporalio/cli/releases and download the appropriate binary for your platform.

Setup

  1. Start Temporal dev server with AccountId search attribute:
temporal server start-dev --search-attribute AccountId=Text
  1. Install dependencies:
go mod download

Exercise Progression

  • Basic Workflow and Activity setup
  • Worker registration and execution
  • Multiple activities (withdraw, deposit, refund)
  • Signal-based approval mechanism
  • workflow.Await() for conditional waiting
  • Basic error handling and compensation
  • Query methods for workflow state inspection
  • Status tracking throughout execution
  • External workflow monitoring
  • Signal vs Query differences
  • Custom Search Attributes (AccountId)
  • Upsert Search Attributes from workflows
  • Workflow filtering and discovery
  • Activity summaries for better observability
  • Enhanced monitoring in Temporal Web UI
  • Unit tests with testsuite
  • Time skipping for fast tests
  • Activity mocking with testify/mock
  • Search attribute registration in tests
  • Manual retry pattern using signals
  • Invalid data handling scenarios
  • Disabling automatic retries
  • Interactive retry commands

Running Exercises

Exercise 1 (Hello Temporal)

# Start worker
go run solution1/worker/main.go
# Run workflow (in another terminal)
go run solution1/starter/main.go

Exercise 2 (Money Transfer Basics)

# Start worker
go run solution2/worker/main.go
# Run workflow (in another terminal)
go run solution2/starter/main.go

Exercise 3 (Query Handlers)

# Start worker
go run solution3/worker/main.go
# Run workflow (in another terminal)
go run solution3/starter/main.go

Exercise 4 (Visibility & Monitoring)

# Start worker
go run solution4/worker/main.go
# Run workflow (in another terminal)
go run solution4/starter/main.go

Exercise 5 (User Metadata & Activity Summaries)

# Start worker
go run solution5/worker/main.go
# Run workflow (in another terminal)
go run solution5/starter/main.go

Exercise 6 (Testing Strategy)

# Run tests
go test ./solution6 -v

Exercise 7 (Manual Activity Retry)

# Start worker
go run solution7/worker/main.go
# Run workflow (in another terminal)
go run solution7/starter/main.go
# Or send retry signal manually
temporal workflow signal \
  --workflow-id money-transfer-workflow \
  --name retry \
  --input '{"Key":"fromAccount","Value":"account-123"}'

Key Features Implemented

  • Go Structs: Modern data structures
  • Activity Retry: Configurable retry policies
  • Signal/Query: Workflow interaction patterns
  • Search Attributes: Custom filtering
  • Activity Summaries: Enhanced observability
  • Compensation: Saga pattern for rollbacks
  • Testing: Time-skipping unit tests with testify
  • Error Handling: Distinguishes activity vs workflow failures
  • Manual Retry: Signal-based retry for failed activities

Project Structure

.
├── solution1/          # Hello Temporal
├── solution2/          # Money Transfer Basics
├── solution3/          # Query Handlers
├── solution4/          # Visibility & Monitoring
├── solution5/          # Activity Summaries
├── solution6/          # Testing Strategy
├── solution7/          # Manual Activity Retry
└── go.mod

Each solution contains:

  • workflow.go - Workflow implementation
  • activities.go - Activity implementations
  • models.go - Data structures
  • worker/main.go - Worker startup
  • starter/main.go - Workflow starter
  • workflow_test.go - Unit tests (solution6)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages