GithubHelp home page GithubHelp logo

jhecking / samples-typescript Goto Github PK

View Code? Open in Web Editor NEW

This project forked from temporalio/samples-typescript

0.0 0.0 0.0 2.57 MB

License: Other

Shell 16.05% JavaScript 22.67% TypeScript 59.03% CSS 0.39% HTML 0.72% Dockerfile 1.13%

samples-typescript's Introduction

samples-typescript

Each directory in this repo is a sample Temporal project built with the TypeScript SDK (see docs and API reference).

Running

In browser

The fastest way to try out these samples is running them in the browser:

Locally

Run Temporal Server:

git clone https://github.com/temporalio/docker-compose.git temporal
cd temporal
docker-compose up -d

Use Node version 14+:

Run the hello-world sample:

git clone https://github.com/temporalio/samples-typescript.git
cd samples-typescript/hello-world
npm i
npm start

and in another terminal:

npm run workflow

Scaffold

To scaffold a new project from one of these samples, run:

npx @temporalio/create@latest my-project --sample sample-name

or:

npx @temporalio/create@latest my-project

and you'll be given the list of sample options.

Samples

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: Use a unique task queue per Worker to have certain Activities only run on that specific Worker. For instance for a file processing Workflow, where the first Activity is downloading a file, and subsequent Activities need to operate on that file. (And if multiple Workers are on the same queue, subsequent Activities may be run on a different machine that doesn't have the downloaded file.)

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: Create, set, upsert, and read Search Attributes.
  • Subscriptions

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.

Test APIs

Full-stack apps

  • Next.js:
    • One-click e-commerce: Buy an item with one click, and the Workflow will wait 5 seconds to see if the user cancels before it executes the order.

External apps & libraries

The below projects are maintained outside this repo and may not be up to date.

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 get started developing, run:

git clone https://github.com/temporalio/samples-typescript.git
cd samples-typescript
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/client" = "NEW_VERSION_HERE"' $f | sponge $f; done
for f in !(monorepo-folders)/package.json; do jq '.dependencies."@temporalio/worker" = "NEW_VERSION_HERE"' $f | sponge $f; done
for f in !(monorepo-folders)/package.json; do jq '.dependencies."@temporalio/workflow" = "NEW_VERSION_HERE"' $f | sponge $f; done
for f in !(monorepo-folders)/package.json; do jq '.dependencies."@temporalio/activity" = "NEW_VERSION_HERE"' $f | sponge $f; done
jq '.dependencies."@temporalio/common" = "NEW_VERSION_HERE"' ejson/package.json | sponge ejson/package.json;
jq '.dependencies."@temporalio/common" = "NEW_VERSION_HERE"' encryption/package.json | sponge encryption/package.json;
jq '.dependencies."@temporalio/common" = "NEW_VERSION_HERE"' grpc-calls/package.json | sponge grpc-calls/package.json;
jq '.devDependencies."@temporalio/client" = "NEW_VERSION_HERE"' package.json | sponge package.json;
jq '.devDependencies."@temporalio/testing" = "NEW_VERSION_HERE"' activities-examples/package.json | sponge activities-examples/package.json;
jq '.devDependencies."@temporalio/testing" = "NEW_VERSION_HERE"' timer-examples/package.json | sponge timer-examples/package.json;
jq '.dependencies."@temporalio/interceptors-opentelemetry" = "NEW_VERSION_HERE"' interceptors-opentelemetry/package.json | sponge interceptors-opentelemetry/package.json;
jq '.dependencies."@temporalio/client" = "NEW_VERSION_HERE"' monorepo-folders/packages/backend-apis/package.json | sponge monorepo-folders/packages/backend-apis/package.json;
jq '.dependencies."@temporalio/worker" = "NEW_VERSION_HERE"' monorepo-folders/packages/temporal-worker/package.json | sponge monorepo-folders/packages/temporal-worker/package.json;
jq '.dependencies."@temporalio/activity" = "NEW_VERSION_HERE"' monorepo-folders/packages/temporal-workflows/package.json | sponge monorepo-folders/packages/temporal-workflows/package.json;
jq '.dependencies."@temporalio/workflow" = "NEW_VERSION_HERE"' monorepo-folders/packages/temporal-workflows/package.json | sponge monorepo-folders/packages/temporal-workflows/package.json;

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.

samples-typescript's People

Contributors

antmendoza avatar bergundy avatar edgji avatar guychouk avatar jbreiding avatar joshspicer avatar joshuakgoldberg avatar lorensr avatar mend-for-github-com[bot] avatar mnichols avatar mrturck avatar nonissue avatar rachfop avatar sjwarner avatar swyxio avatar vkarpov15 avatar yodon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.