Skip to content

Conversation

Shy
Copy link
Contributor

@Shy Shy commented Oct 1, 2025

This commit adds 5 examples:

  1. MultipleActivities Example: Demonstrates activity orchestration through an e-commerce order fulfillment workflow
  2. ErrorHandling Example: Showcases error handling and compensation patterns through a travel booking workflow with three scenarios.
  3. Signals Example: Demonstrates message passing capabilities through an order processing workflow.
  4. Async Example: Demonstrates parallel and concurrent activity execution in Temporal.
  5. Schedule Example: Demonstrates Temporal scheduling with live NASA APIs to monitor the International Space Station.
  6. Child Workflows - Demonstrates parent and child workflow orchestration through a pizza restaurant order fulfillment system with parallel and sequential child workflows.

@Shy Shy changed the title Add MultipleActivities and ErrorHandling examples Added examples. Oct 1, 2025
@FranzBusch FranzBusch added the semver/none No version bump required. label Oct 1, 2025
Shy and others added 8 commits October 2, 2025 11:40
This commit adds two comprehensive examples showcasing the Swift Temporal SDK:

1. **MultipleActivities Example**: Demonstrates activity orchestration through
   a realistic e-commerce order fulfillment workflow with six sequential steps
   (inventory check, payment processing, reservation, shipment creation,
   customer notification, and status update). Each activity uses tailored
   retry policies appropriate for its operation type.

2. **ErrorHandling Example**: Showcases error handling and compensation patterns
   through a travel booking workflow with three scenarios:
   - Retry with exponential backoff for transient failures
   - Saga pattern for successful distributed transaction compensation
   - Workflow failure when compensation itself fails

Both examples follow Temporal best practices:
- Structured Codable types (no string parsing or tuple encoding)
- Deterministic workflows (no print statements in workflow code)
- Realistic business scenarios demonstrating SDK value
- Clear retry policies and error handling patterns
- Temporal UI links for easy workflow monitoring

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@Shy Shy force-pushed the example_expansion branch from b4c0ee9 to c3c90f5 Compare October 2, 2025 10:41
@heckj
Copy link

heckj commented Oct 2, 2025

Hey Shy - adding in the executable targets for the examples makes them super easy access, but comes at the cost of extending the build time for the project overall, which may be undesirable. A pattern that I've seen used in the broader Swift ecosystem is to make a separate Swift package manifest in an Examples/ directory, referencing the source in there, that's built and managed separately from the main Package.swift for the project. The general gist looks remarkably similar to your addition, but where you're referencing the target as a dependency for the example binaries, you'd use a local package reference - something like ../ to represent "hey, depend on the package in the directory above this one.

This'll also sort some of the breaking tests that are complaining about public API changes. If you head this direction, it might be worth adding some additional CI build checks to verify that the examples all compile correctly, since that wouldn't normally be verified with a top-level package build if it's a separate package.

The last suggestion is taking a quick peek and run through a compilation run on Linux, where some of the Foundation types (URLSession, in particular) have some different "API shapes" that look to be causing some compilation issues. I used container to run the compilation within the released 6.2 image, and it reflected the build errors showing the tests above.

The command, for reference (it's my handy go-to check a Linux compilation), referencing container:

container run -it -c 4 -m 8g -v "$(pwd):/src" -w src/ swift:6.2-noble

The other technique I like to use to check package builds in Linux is a bit larger in terms of moving parts - setting up a .devContainer for the repository, and opening it in VS Code.

You can see the full set of issues that don't compile in Linux in the complication checks in GH Actions, but a short snippet to illustrate from my local build as well:

/src/Examples/AsyncActivities/AsyncActivitiesExample.swift:44:46: error: type 'URLSession' (aka 'AnyObject') has no member 'shared'
 42 |         request.httpMethod = "GET"
 43 |
 44 |         let (data, _) = try await URLSession.shared.data(for: request)
    |                                              `- error: type 'URLSession' (aka 'AnyObject') has no member 'shared'
 45 |         let decoder = JSONDecoder()
 46 |         return try decoder.decode([FilmPermitActivities.FilmPermit].self, from: data)
/src/Examples/AsyncActivities/FilmPermitActivities.swift:102:23: error: cannot find 'URLRequest' in scope
100 |
101 |         let url = URL(string: "https://data.cityofnewyork.us/resource/tg4x-b46p.json?$limit=\(input)")!
102 |         var request = URLRequest(url: url)
    |                       `- error: cannot find 'URLRequest' in scope
103 |         request.timeoutInterval = 30
104 |         request.httpMethod = "GET"

Functionally, I thought all the examples were easy to read and parse through. For me, I'd tend to lean a bit into a touch more narrative content - working to make full sentences rather than leaning on fragments and such, but it's perfectly clear and the differences between examples are easy to understand, and - I think - from the examples you provide, understand "Ah, this is the pattern to do... XYZ"

@Shy
Copy link
Contributor Author

Shy commented Oct 3, 2025

@heckj Thanks for the feedback. This is very much appreciated.

I've added in a new package.swift for the examples directory. I've also resolved the linux build issues and confirm everything works with the command you shared. Franz has asked to let him handle the CI build checks so I'll leave those alone for now.

@FranzBusch FranzBusch merged commit a7d25d5 into apple:main Oct 3, 2025
20 of 22 checks passed
@Shy Shy deleted the example_expansion branch October 3, 2025 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver/none No version bump required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants