Skip to content

field-energy/temporalio-samples-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4586bc3 Β· Mar 8, 2023
Jan 24, 2022
Mar 24, 2022
Jan 12, 2022
Apr 20, 2022
Apr 20, 2022
Mar 24, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 7, 2022
Apr 20, 2022
Apr 7, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Mar 24, 2022
Apr 7, 2022
Apr 20, 2022
Apr 20, 2022
Apr 7, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 20, 2022
Apr 3, 2022
Dec 15, 2021
Feb 18, 2022
Feb 24, 2022
Sep 16, 2021
Apr 20, 2022
Sep 12, 2021
Apr 3, 2022
Feb 28, 2022
Nov 1, 2021
Mar 8, 2023
Apr 14, 2022

Repository files navigation

samples-typescript

Samples

Each directory in this repo is a sample Temporal project built with the TypeScript SDK.

  • The fastest way to try these out is starting Temporal and running these samples in the browser:
  • To run these samples locally, go through the prerequisites listed in our Getting Started docs.
  • To scaffold a new project from one of these samples, run:
    npx @temporalio/create@latest my-project-name
    # or npx @temporalio/create@latest my-project-name --sample sample-name

Basic

API demos

Activity APIs and Design Patterns

  • Activities Examples:
    • makeHTTPRequest: Make an external HTTP request in an Activity (using axios)
    • cancellableFetch: Make a cancellable HTTP request with cancellationSignal.
  • Activity Cancellation and Heartbeating: Heartbeat progress for long running activities and cancel them.
  • Dependency Injection: Share dependencies between activities (for example, when you need to initialize a database connection once and then pass it to multiple activities).
  • Sticky Activities: Dynamically assign task queue names to ensure activities execute sequentially on the same machine (eg for CI/CD, file processing workflows).

Workflow APIs

  • Timers:
    • The progress example demonstrates how to use the sleep function from @temporalio/workflow.
    • Timer Examples:
      • Send a notification to the customer if their order is taking longer than expected (using a Promise.race between the order activity and sleep).
      • Create an UpdatableTimer that can be slept on, and at the same time, have its duration updated via Signals.
  • Signals and Triggers:
    • The Signals and Queries example demonstrates the usage of Signals, Queries, and Workflow Cancellation.
    • Async activity completion: Example of an Expense reporting Workflow that communicates with a server API. Shows how to kick off a Workflow and manually complete it at an arbitrarily later date.
  • Cron Workflows: Schedule a cron job.
  • Child Workflows: Start and control Child Workflows.
  • Infinite Workflows: Use the continueAsNew API for indefinitely long running Workflows.
  • Search Attributes: Set up Search Attributes (an experimental feature for now).

Production APIs

  • Production Build: Build code in advance for faster Worker startup times.
  • Debugging: The replay-history sample shows how to retrieve Workflow Event History and debug it using the runReplayHistory Worker API (video).
  • Patching: Patch in new Workflow code when making updates to Workflows that have executions in progress in production.
  • Logging: Use Sinks to extract data out of Workflows for logging/metrics/tracing purposes.
  • Instrumentation: Use a winston logger to get logs out of all SDK components and get metrics and traces out of Rust Core.
  • Protobufs: Use Protobufs.
  • Custom Payload Converter: Customize data serialization by creating a PayloadConverter that uses EJSON to convert Dates, binary, and regexes.

Advanced APIs

  • Interceptors
    • OpenTelemetry: Use the Interceptors feature to add OpenTelemetry metrics reporting to your workflows.
    • Query Subscriptions: Use Redis Streams, Immer, and SDK Interceptors to subscribe to Workflow state.
  • gRPC calls: Make raw gRPC calls for advanced queries not covered by the WorkflowClient API.

Fullstack Apps

Contributing

External contributions are very welcome! πŸ€— (Big thank you to those who have already contributed πŸ™)

Before submitting a major PR, please find consensus on it in Issues.

To start, run these commands in the root directory:

npm install
npm run prepare
npm run bootstrap

Prettier and ESLint are run on each commit, but you can also run them manually:

npm run format
npm run lint

Upgrading the SDK version

shopt -s extglob
for f in !(monorepo-folders)/package.json; do jq '.dependencies.temporalio = "NEW_VERSION_HERE"' $f | sponge $f; done
jq '.devDependencies."@temporalio/client" = "NEW_VERSION_HERE"' package.json | sponge package.json;
jq '.dependencies."@temporalio/interceptors-opentelemetry" = "NEW_VERSION_HERE"' interceptors-opentelemetry/package.json | sponge interceptors-opentelemetry/package.json;
for f in monorepo-folders/packages/!(frontend-ui)/package.json; do jq '.dependencies.temporalio = "NEW_VERSION_HERE"' $f | sponge $f; done

Config files

Also on each commit, config files from .shared/ are copied into each sample directory, overwriting the sample directory's config files (with a few exceptions listed in .scripts/copy-shared-files.mjs). So if you're editing config files, you usually want to be editing the versions in .shared/.

The .post-create file is a chalk template that is displayed in the command line after someone uses npx @temporalio/create. If you're adding a sample that requires different instructions from the default message, then add your sample name to POST_CREATE_EXCLUDE and your message template to your-sample/.post-create.

About

Fork of the temporalio/samples-typescript repo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 55.7%
  • JavaScript 24.2%
  • Shell 17.7%
  • Dockerfile 1.2%
  • Other 1.2%