Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close all explicitly created NativeConnection #395

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions empty/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,30 @@ async function run() {
address: 'localhost:7233',
// TLS and gRPC metadata configuration goes here.
});
// Step 2: Register Workflows and Activities with the Worker.
const worker = await Worker.create({
connection,
namespace: 'default',
taskQueue: TASK_QUEUE_NAME,
// Workflows are registered using a path as they run in a separate JS context.
workflowsPath: require.resolve('./workflows'),
activities,
});
try {
// Step 2: Register Workflows and Activities with the Worker.
const worker = await Worker.create({
connection,
namespace: 'default',
taskQueue: TASK_QUEUE_NAME,
// Workflows are registered using a path as they run in a separate JS context.
workflowsPath: require.resolve('./workflows'),
activities,
});

// Step 3: Start accepting tasks on the Task Queue specified in TASK_QUEUE_NAME
//
// The worker runs until it encounters an unexpected error or the process receives a shutdown signal registered on
// the SDK Runtime object.
//
// By default, worker logs are written via the Runtime logger to STDERR at INFO level.
//
// See https://typescript.temporal.io/api/classes/worker.Runtime#install to customize these defaults.
await worker.run();
// Step 3: Start accepting tasks on the Task Queue specified in TASK_QUEUE_NAME
//
// The worker runs until it encounters an unexpected error or the process receives a shutdown signal registered on
// the SDK Runtime object.
//
// By default, worker logs are written via the Runtime logger to STDERR at INFO level.
//
// See https://typescript.temporal.io/api/classes/worker.Runtime#install to customize these defaults.
await worker.run();
} finally {
// Close the connection once the worker has stopped
await connection.close();
}
}

run().catch((err) => {
Expand Down
21 changes: 13 additions & 8 deletions food-delivery/apps/worker/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ import { namespace, getConnectionOptions } from 'common/lib/temporal-connection'

async function run() {
const connection = await NativeConnection.connect(getConnectionOptions())
const worker = await Worker.create({
workflowsPath: require.resolve('../../../packages/workflows/'),
activities,
connection,
namespace,
taskQueue,
})
try {
const worker = await Worker.create({
workflowsPath: require.resolve('../../../packages/workflows/'),
activities,
connection,
namespace,
taskQueue,
})

await worker.run()
await worker.run()
} finally {
// Close the connection once the worker has stopped
await connection.close()
}
}

run().catch((err) => {
Expand Down
25 changes: 14 additions & 11 deletions hello-world-mtls/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,21 @@ async function run({
},
},
});
try {
const worker = await Worker.create({
connection,
namespace,
workflowsPath: require.resolve('./workflows'),
activities,
taskQueue,
});
console.log('Worker connection successfully established');

const worker = await Worker.create({
connection,
namespace,
workflowsPath: require.resolve('./workflows'),
activities,
taskQueue,
});
console.log('Worker connection successfully established');

await worker.run();
await connection.close();
await worker.run();
} finally {
// Close the connection once the worker has stopped
await connection.close();
}
}

run(getEnv()).catch((err) => {
Expand Down
41 changes: 23 additions & 18 deletions hello-world/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,30 @@ async function run() {
address: 'localhost:7233',
// TLS and gRPC metadata configuration goes here.
});
// Step 2: Register Workflows and Activities with the Worker.
const worker = await Worker.create({
connection,
namespace: 'default',
taskQueue: 'hello-world',
// Workflows are registered using a path as they run in a separate JS context.
workflowsPath: require.resolve('./workflows'),
activities,
});
try {
// Step 2: Register Workflows and Activities with the Worker.
const worker = await Worker.create({
connection,
namespace: 'default',
taskQueue: 'hello-world',
// Workflows are registered using a path as they run in a separate JS context.
workflowsPath: require.resolve('./workflows'),
activities,
});

// Step 3: Start accepting tasks on the `hello-world` queue
//
// The worker runs until it encounters an unexpected error or the process receives a shutdown signal registered on
// the SDK Runtime object.
//
// By default, worker logs are written via the Runtime logger to STDERR at INFO level.
//
// See https://typescript.temporal.io/api/classes/worker.Runtime#install to customize these defaults.
await worker.run();
// Step 3: Start accepting tasks on the `hello-world` queue
//
// The worker runs until it encounters an unexpected error or the process receives a shutdown signal registered on
// the SDK Runtime object.
//
// By default, worker logs are written via the Runtime logger to STDERR at INFO level.
//
// See https://typescript.temporal.io/api/classes/worker.Runtime#install to customize these defaults.
await worker.run();
} finally {
// Close the connection once the worker has stopped
await connection.close();
}
}

run().catch((err) => {
Expand Down
19 changes: 12 additions & 7 deletions message-passing/execute-update/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ async function run() {
const connection = await NativeConnection.connect({
address: 'localhost:7233',
});
const worker = await Worker.create({
connection,
namespace: 'default',
taskQueue: 'my-task-queue',
workflowsPath: require.resolve('./workflows'),
});
await worker.run();
try {
const worker = await Worker.create({
connection,
namespace: 'default',
taskQueue: 'my-task-queue',
workflowsPath: require.resolve('./workflows'),
});
await worker.run();
} finally {
// Close the connection once the worker has stopped
await connection.close();
}
}

run().catch((err) => {
Expand Down
21 changes: 13 additions & 8 deletions message-passing/introduction/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ async function run() {
const connection = await wo.NativeConnection.connect({
address: 'localhost:7233',
});
const worker = await wo.Worker.create({
connection,
namespace: 'default',
taskQueue: 'my-task-queue',
workflowsPath: require.resolve('./workflows'),
activities,
});
await worker.run();
try {
const worker = await wo.Worker.create({
connection,
namespace: 'default',
taskQueue: 'my-task-queue',
workflowsPath: require.resolve('./workflows'),
activities,
});
await worker.run();
} finally {
// Close the connection once the worker has stopped
await connection.close();
}
}

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