@@ -20,23 +20,39 @@ Create a Worker with `Worker.create()`, passing a connection, the Task Queue to
2020Call ` run() ` to start polling.
2121
2222<!--SNIPSTART typescript-hello-worker-- >
23- [ sleep-for-days /src/worker.ts] ( https://github.com/temporalio/samples-typescript/blob/main/sleep-for-days /src/worker.ts )
23+ [ hello-world /src/worker.ts] ( https://github.com/temporalio/samples-typescript/blob/main/hello-world /src/worker.ts )
2424``` ts
2525import { NativeConnection , Worker } from ' @temporalio/worker' ;
2626import * as activities from ' ./activities' ;
2727
2828async function run() {
29+ // Step 1: Establish a connection with Temporal server.
30+ //
31+ // Worker code uses `@temporalio/worker.NativeConnection`.
32+ // (But in your application code it's `@temporalio/client.Connection`.)
2933 const connection = await NativeConnection .connect ({
3034 address: ' localhost:7233' ,
35+ // TLS and gRPC metadata configuration goes here.
3136 });
3237 try {
38+ // Step 2: Register Workflows and Activities with the Worker.
3339 const worker = await Worker .create ({
3440 connection ,
3541 namespace: ' default' ,
36- taskQueue: ' sleep-for-days' ,
42+ taskQueue: ' hello-world' ,
43+ // Workflows are registered using a path as they run in a separate JS context.
3744 workflowsPath: require .resolve (' ./workflows' ),
3845 activities ,
3946 });
47+
48+ // Step 3: Start accepting tasks on the `hello-world` queue
49+ //
50+ // The worker runs until it encounters an unexpected error or the process receives a shutdown signal registered on
51+ // the SDK Runtime object.
52+ //
53+ // By default, worker logs are written via the Runtime logger to STDERR at INFO level.
54+ //
55+ // See https://typescript.temporal.io/api/classes/worker.Runtime#install to customize these defaults.
4056 await worker .run ();
4157 } finally {
4258 // Close the connection once the worker has stopped
0 commit comments