Skip to content

Commit ab7d13a

Browse files
authored
Merge branch 'main' into tlalfano-patch-1
2 parents bd3d4dc + f7fa833 commit ab7d13a

3 files changed

Lines changed: 58 additions & 39 deletions

File tree

docs/develop/typescript/set-up.mdx

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ This test will confirm that:
156156
Create an Activity file (activity.ts):
157157

158158
```ts
159-
export async function activity(name: string): Promise<string> {
160-
return 'Hello ' + name;
159+
export async function greet(name: string): Promise<string> {
160+
return `Hello, ${name}!`;
161161
}
162162
```
163163

@@ -169,15 +169,16 @@ Create a Workflow file (workflows.ts):
169169

170170
```ts
171171
import { proxyActivities } from '@temporalio/workflow';
172-
import type * as activityTypes from './activity';
172+
// Only import the activity types
173+
import type * as activities from './activities';
173174

174-
const { activity } = proxyActivities<typeof activityTypes>({
175-
startToCloseTimeout: '10 seconds',
175+
const { greet } = proxyActivities<typeof activities>({
176+
startToCloseTimeout: '1 minute',
176177
});
177178

178-
export async function sayHelloWorkflow(name: string): Promise<string> {
179-
const response = await activity(name);
180-
return response;
179+
/** A workflow that simply calls an activity */
180+
export async function example(name: string): Promise<string> {
181+
return await greet(name);
181182
}
182183
```
183184

@@ -191,25 +192,42 @@ If the application itself crashes, Temporal will automatically recreate its pre-
191192
Create a Worker file (worker.ts):
192193

193194
```ts
194-
import { Worker } from '@temporalio/worker';
195-
import * as activitiy from './activity';
195+
import { NativeConnection, Worker } from '@temporalio/worker';
196+
import * as activities from './activities';
196197

197198
async function run() {
198-
// Step 1: Register Workflows and Activities with the Worker and connect to
199-
// the Temporal server.
200-
const worker = await Worker.create({
201-
workflowsPath: require.resolve('./workflows'),
202-
activities: activitiy,
203-
taskQueue: 'my-task-queue',
199+
// Step 1: Establish a connection with Temporal server.
200+
//
201+
// Worker code uses `@temporalio/worker.NativeConnection`.
202+
// (But in your application code it's `@temporalio/client.Connection`.)
203+
const connection = await NativeConnection.connect({
204+
address: 'localhost:7233',
205+
// TLS and gRPC metadata configuration goes here.
204206
});
205-
// Worker connects to localhost by default and uses console.error for logging.
206-
// Customize the Worker by passing more options to create():
207-
// https://typescript.temporal.io/api/classes/worker.Worker
208-
// If you need to configure server connection parameters, see docs:
209-
// https://docs.temporal.io/typescript/security#encryption-in-transit-with-mtls
210-
211-
// Step 2: Start accepting tasks on the my-task-queue queue
212-
await worker.run();
207+
try {
208+
// Step 2: Register Workflows and Activities with the Worker.
209+
const worker = await Worker.create({
210+
connection,
211+
namespace: 'default',
212+
taskQueue: 'hello-world',
213+
// Workflows are registered using a path as they run in a separate JS context.
214+
workflowsPath: require.resolve('./workflows'),
215+
activities,
216+
});
217+
218+
// Step 3: Start accepting tasks on the `hello-world` queue
219+
//
220+
// The worker runs until it encounters an unexpected error or the process receives a shutdown signal registered on
221+
// the SDK Runtime object.
222+
//
223+
// By default, worker logs are written via the Runtime logger to STDERR at INFO level.
224+
//
225+
// See https://typescript.temporal.io/api/classes/worker.Runtime#install to customize these defaults.
226+
await worker.run();
227+
} finally {
228+
// Close the connection once the worker has stopped
229+
await connection.close();
230+
}
213231
}
214232

215233
run().catch((err) => {
@@ -239,31 +257,32 @@ This final step will validate that everything is working correctly with your fil
239257
Create a separate file called `client.ts`.
240258

241259
```ts
242-
import { Connection, WorkflowClient } from '@temporalio/client';
243-
import { sayHelloWorkflow } from './workflows';
260+
import { Client, Connection } from '@temporalio/client';
261+
import { nanoid } from 'nanoid';
262+
import { example } from './workflows';
244263

245264
async function run() {
246-
// Connect to the default Server location (localhost:7233)
247-
const connection = await Connection.connect();
265+
// Connect to the default Server location
266+
const connection = await Connection.connect({ address: 'localhost:7233' });
248267
// In production, pass options to configure TLS and other settings:
249268
// {
250-
// address: 'foo.bar.tmprl.cloud',
251-
// tls: {}
269+
// address: 'foo.bar.tmprl.cloud',
270+
// tls: {}
252271
// }
253272

254-
const client = new WorkflowClient({
273+
const client = new Client({
255274
connection,
256275
// namespace: 'foo.bar', // connects to 'default' namespace if not specified
257276
});
258277

259-
const handle = await client.start(sayHelloWorkflow, {
278+
const handle = await client.workflow.start(example, {
279+
taskQueue: 'hello-world',
260280
// type inference works! args: [name: string]
261281
args: ['Temporal'],
262-
taskQueue: 'my-task-queue',
263-
// in practice, use a meaningful business id, eg customerId or transactionId
264-
workflowId: 'my-first-workflow',
282+
// in practice, use a meaningful business ID, like customerId or transactionId
283+
workflowId: 'workflow-' + nanoid(),
265284
});
266-
console.log('Started workflow ' + handle.workflowId);
285+
console.log(`Started workflow ${handle.workflowId}`);
267286

268287
// optional: wait for client result
269288
console.log(await handle.result()); // Hello, Temporal!

docs/encyclopedia/nexus-operations.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ Callers can then migrate to the new version in their normal deployment schedule.
332332

333333
:::tip SUPPORT, STABILITY, and DEPENDENCY INFO
334334

335-
Using a [Conflict-Policy of Use-Existing](/workflow-execution/workflowid-runid#workflow-id-conflict-policy) with the [New-Workflow-Run-Operation](/nexus/operations#sdk-support) SDK helper is currently a [Pre-release](/evaluate/development-production-features/release-stages#pre-release) feature.
335+
Using a [Conflict-Policy of Use-Existing](/workflow-execution/workflowid-runid#workflow-id-conflict-policy) with the [New-Workflow-Run-Operation](/nexus/operations#sdk-support) SDK helper is currently a [Public Preview](/evaluate/development-production-features/release-stages#public-preview) feature.
336336

337337
:::
338338

docs/encyclopedia/nexus.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ Nexus supports multi-level Nexus calls, for example:
9292

9393
- Workflow A → Nexus Operation 1 → Workflow B → Nexus Operation 2 → Workflow C
9494

95-
## Pre-release features
95+
## Public Preview features
9696

9797
:::tip SUPPORT, STABILITY, and DEPENDENCY INFO
9898

99-
The following Nexus features are currently in [Pre-release](/evaluate/development-production-features/release-stages#pre-release).
99+
The following Nexus features are currently in [Public Preview](/evaluate/development-production-features/release-stages#public-preview).
100100

101101
:::
102102

0 commit comments

Comments
 (0)