A Temporal workflow for a sample e-commerce order fulfillment use case. This demo showcases Temporal's powerful durability and interactive capabilities.
The sample is configured by default to connect to a local Temporal Server running on localhost:7233
temporal server start-dev
To instead connect to Temporal Cloud, set the following environment variables, replacing them with your own Temporal Cloud credentials.
With mTLS:
TEMPORAL_ADDRESS=testnamespace.sdvdw.tmprl.cloud:7233
TEMPORAL_NAMESPACE=testnamespace.sdvdw
TEMPORAL_CLIENT_CERT_PATH="/path/to/file.pem"
TEMPORAL_CLIENT_KEY_PATH="/path/to/file.key"
With API key:
TEMPORAL_ADDRESS=us-west-2.aws.api.temporal.io:7233
TEMPORAL_NAMESPACE=testnamespace.sdvdw
TEMPORAL_API_KEY="your-api-key"
# ensure TEMPORAL_CLIENT_CERT_PATH and TEMPORAL_CLIENT_KEY_PATH are not set
npm install
to install dependencies.
Run npm run start
to start the Worker. (You can also get Nodemon to watch for changes and restart the worker automatically by running npm run start.watch
.)
Run npm run workflow
to run the Workflow.
See demo
folder for different scenarios that will be live-coded into workflows.ts
:
- Happy path (
demo/workflows1.ts
) - API Downtime (uncomment inventory code)
- Invalid order troubleshooting, set cc expiry in
starter.ts
to12/23
- Human in the loop, send
approveOrder
signal (demo/workflows2.ts
) - Approve or expire order (
demo/workflows3.ts
) - Bug in workflow, add
throw Error('workflow bug!')
in workflow code - Generate invalid orders
npm run workflow -- --numOrders 50 --invalidPercentage 20
(note the--
to pass args to the script)- This will generate 50 orders with 20% invalid orders
- Uncomment bug fix in
api.ts
and run again to fix workflows