38 lines
1.4 KiB
JavaScript
38 lines
1.4 KiB
JavaScript
|
import { NativeConnection, Worker } from '@temporalio/worker'
|
||
|
import * as activities from './temporal.activities.js'
|
||
|
import path from 'node:path'
|
||
|
|
||
|
async function run() {
|
||
|
// Step 1: Establish a connection with Temporal server.
|
||
|
//
|
||
|
// Worker code uses `@temporalio/worker.NativeConnection`.
|
||
|
// (But in your application code it's `@temporalio/client.Connection`.)
|
||
|
const connection = await NativeConnection.connect({
|
||
|
address: 'temporal-frontend.futureporn.svc.cluster.local',
|
||
|
// TLS and gRPC metadata configuration goes here.
|
||
|
});
|
||
|
// Step 2: Register Workflows and Activities with the Worker.
|
||
|
const worker = await Worker.create({
|
||
|
connection,
|
||
|
namespace: 'futureporn',
|
||
|
taskQueue: 'hello-world',
|
||
|
// Workflows are registered using a path as they run in a separate JS context.
|
||
|
workflowsPath: path.join(import.meta.dirname, './temporal.workflow.js'),
|
||
|
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();
|
||
|
}
|
||
|
|
||
|
run().catch((err) => {
|
||
|
console.error(err);
|
||
|
process.exit(1);
|
||
|
})
|