Repository navigation
Add Go, Python, and Java Saga design-pattern samples - #320
Merged
Merged
Conversation
Ports the Saga pattern from temporal-sa/temporal-design-patterns into runnable, tested samples for Go, Python, and Java, matching the existing TypeScript sample's request, Task Queue, log lines, and outcome. Each one has a runner.json manifest and unit tests, and wraps its Workflow in @@@SNIPSTART markers for the docs.temporal.io Saga pattern page. All four Workflows now run compensations after cancellation (disconnected context, CancelledError catch, detached scope, non-cancellable scope) and keep compensating when one compensation fails, as the docs page's best practices say. Tests cover success, failure at different steps, a failing compensation, and cancellation. run-design-patterns.yml gains Go, Python, and Java jobs that run the unit tests and each manifest end to end, and the TypeScript job now runs the Saga tests. The runner script exports TEMPORAL_ADDRESS so samples, which now load envconfig, connect to the run's own dev server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds runnable, tested Saga samples for Go, Python, and Java so the Saga pattern page can sync all four language tabs with Snipsync. The TypeScript tab already syncs from
typescript-sandbox/src/design-patterns/saga/.The code is ported from
sandbox-runner/patterns/saga/in temporal-sa/temporal-design-patterns, the project these docs pages came from, and changed to match the existing TypeScript sample and the page's guidance:design-patterns-sagaTask Queue, theCompensation: ...log lines, and the outcome match TypeScript.addBankAccountfails with a non-retryable error, the Workflow runs the three compensations in reverse order, and then re-throws, so the run endsFAILED. The temporal-sa Java and Python versions returned a status string instead.workflow.NewDisconnectedContext, Python catchesasyncio.CancelledError, Java usesWorkflow.newDetachedCancellationScope, and TypeScript usesCancellationScope.nonCancellable.Saga.Options.setContinueWithError(true).The TypeScript Workflow gets the same two changes so the page's four tabs teach the same thing.
Layout
go-sandbox/design-patterns/saga/(packagesaga, plusworker/andstarter/)go-pattern-saga-pattern-workflowpython-sandbox/design-patterns/saga/(ownpyproject.tomlanduv.lock, like the cloud quickstarts)python-pattern-saga-pattern-workflowjava-sandbox/design-patterns/saga/(ownpom.xml, Temporal SDK 1.41.1)java-pattern-saga-pattern-workflowEach directory has a
runner.jsonmanifest, which the docs live runner will also use.CI
run-design-patterns.ymlgains Go, Python, and Java jobs. Each runs that language's design-pattern unit tests and then every manifest end to end.saga.test.ts, which nothing ran before.ci-on-pr.ymlJava job's*/*/pom.xmlglob already compiles the new Java module.run-design-pattern.shexportsTEMPORAL_ADDRESS=localhost:$port. The samples, including the TypeScript Worker, now load connection settings with envconfig, so a run on a non-defaultTEMPORAL_PORTreaches its own dev server instead of whatever is on 7233.Testing
Run locally on macOS, with JDK 21 for Java:
go test ./design-patterns/...uv run pytest(Python)mvn test(Java)saga.test.ts(TypeScript)run-design-pattern.shon all four manifests withTEMPORAL_PORT=7243: allPASS, statusFAILEDas expected, and the compensation lines in order.go build ./... && go vet ./...,compileall,npx tsc --noEmit, andactionlinton the workflow.A docs PR that syncs the page will follow as a draft until this merges.