Skip to content

Commit

Permalink
Merge branch 'addgrpcdemo'
Browse files Browse the repository at this point in the history
  • Loading branch information
swyxio committed Jan 21, 2022
2 parents 781b758 + a1923f8 commit 2ed97a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions grpc-calls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Under the hood of a `WorkflowClient`, the `Connection` is actually powered by a
This Service is capable of making a wider range of introspection calls (as per [the API reference](https://typescript.temporal.io/api/classes/proto.temporal.api.workflowservice.v1.WorkflowService-1#methods)).

This demo shows you how to make those raw gRPC calls to Temporal Server.
Just look at `client.ts` as that's the only thing that is different.
Full docs are available at https://docs.temporal.io/docs/typescript/clients/#advanced-making-raw-grpc-calls

### Running this sample

1. Make sure Temporal Server is running locally (see the [quick install guide](https://docs.temporal.io/docs/server/quick-install/)).
1. `npm install` to install dependencies.
1. `npm run start.watch` to start the Worker.
1. In another shell, `npm run workflow` to run the Workflow Client.

The client should log the Workflow ID that is started, and you should see it reflected in Temporal Web UI.
11 changes: 8 additions & 3 deletions grpc-calls/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Connection, WorkflowClient } from '@temporalio/client';
import { example } from './workflows';
import { ApplicationFailure, defaultDataConverter, errorToFailure, msToTs, RetryState } from '@temporalio/common';
import { Connection } from '@temporalio/client';
import { defaultDataConverter } from '@temporalio/common';

async function run() {
// @@@SNIPSTART typescript-grpc-call-basic
const connection = new Connection();

// // normal way of starting a Workflow, with a WorkflowClient
Expand All @@ -19,24 +19,29 @@ async function run() {
workflowType: { name: 'example' },
input: { payloads: await defaultDataConverter.toPayloads('Temporal') },
});
// @@@SNIPEND

await sleep();

// @@@SNIPSTART typescript-grpc-call-getWorkflowExecutionHistory
// no equivalent call in client, this is only available as an SDK call
const res = await connection.service.getWorkflowExecutionHistory({
execution: { workflowId },
namespace: 'default',
});
console.log(res.history);
// @@@SNIPEND

await sleep();

// @@@SNIPSTART typescript-grpc-call-listWorkflowExecutions
// no equivalent call in client, this is only available as an SDK call
// requires ElasticSearch
const results = await connection.service.listWorkflowExecutions({
namespace: 'default',
});
console.table(results.executions);
// @@@SNIPEND
}

run().catch((err) => {
Expand Down

0 comments on commit 2ed97a2

Please sign in to comment.