Skip to content

temporal-sa/temporal-money-transfer-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Money Transfer Example

Demos various aspects of Temporal using the Typescript SDK.

https://transfer.tmprl-demo.cloud/

A Java SDK version of this example is also available.

UI Screenshot

Configuration

(optional if using local Temporal dev server)

  • server/ contains .env_example. Copy it to .env.development and change settings to match your temporal installation.
  • STRIPE_SECRET_KEY is optional (use if you want to run simulated charges against the Stripe API)
  • ui/ contains .env_example. Copy it to .env.development and change settings to point to your API (server) location (default is / which should be fine)
  • The server respects .env.production if NODE_ENV is "production" (and the Svelte app is built using npm run build such as in the Dockerfile)

Run a Workflow

Run a Temporal Server (Guide)

  • brew install temporal
  • temporal server start-dev (Temporal Server web UI: localhost:8233)

Install Node dependencies:

  • cd server/

  • npm install

  • cd ui/

  • npm install

Run workers

  • Run a workflow worker:
    • cd server
    • npm run worker

Run API and Web UI (localhost:3000)

  • nodemon /server/index.ts (from the project root directory)

Demo various failures and recoveries

A dropdown menu simulates the following scenarios

Happy Path

  • The transfer will run to completion

Require Human-In-Loop Approval

The transfer will pause and wait for approval. If the user doesn't approve the transfer within a set time, the workflow will fail.

Approve a transfer using Signals

You can also do this through the temporal cli:

temporal workflow signal \
--query 'ExecutionStatus="Running" and WorkflowType="moneyTransferWorkflow"' \
--name approveTransfer \
--reason 'approving transfer'

Approve a transfer using Updates (COMING SOON)

You can do this through the temporal cli:

temporal workflow update \
 --env prod \
 --workflow-id TRANSFER-XXX-XXX \
 --name approveTransferUpdate

The workflow's Update function has a validator. It will reject an Update if:

  • The transfer isn't waiting for approval
  • The transfer has already been approved

Simulate a Bug in the Workflow (recoverable failure)

In ./server/temporal/workflows.ts, uncomment the line // throw new Error('Workflow bug!');. Re-comment it and restart the worker for the workflow to recover.

Simulate API Downtime (recover on 5th attempt)

Will introduce artifical delays in the withdraw activity's API calls. This will cause activity retries. After 5 retries, the delay will be removed and the workflow will proceed.

Invalid Account (unrecoverable failure)

Introduces an unrecoverable failure in the deposit activity (invalid account). The workflow will fail after running compensation activities (undoWithdraw).

Schedule a recurring transfer

Creates a Schedule that will run a set of workflows on a cadence.

Produces a schedule ID, which you can inspect in the Temporal UI's "Schedules" menu.

Enable Encryption

Set ENCRYPT_PAYLOADS to "true" in the configuration file (see Configuration section above).

You can decrypt these payloads in Temporal Cloud's UI/cli using the codec server: https://codec.tmprl-demo.cloud (source). Ensure you switch on "Pass the user access token with your endpoint" setting in the Codec Configuration in Temporal Cloud. Note: The codec server is only compatible with workflows running in Temporal Cloud.

List failed workflows

temporal workflow list --env prod -q 'ExecutionStatus="Failed" OR ExecutionStatus="Terminated"'

(Advanced) Debug/replay Workflow histories with the Temporal VSCode Extension

  • Open /server as a VSCode project
  • Run the replayer on a downloaded workflow JSON file