52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { Worker } from '@temporalio/worker';
|
|
import { URL } from 'url';
|
|
import path from 'path';
|
|
import * as activities from '../temporal-workflows/src/activities.js';
|
|
// import * as workflows from 'temporal-workflows/workflows.js';
|
|
import 'dotenv/config'
|
|
|
|
if (!process.env.TEMPORAL_TASK_QUEUE) throw new Error('TEMPORAL_TASK_QUEUE was missing from env');
|
|
|
|
async function run() {
|
|
const workflowsPath = new URL(
|
|
`../temporal-workflows/src/workflows${path.extname(import.meta.url)}`,
|
|
import.meta.url
|
|
).pathname
|
|
console.log(`workflowsPath=${workflowsPath}`)
|
|
|
|
// const workflowOption = () =>
|
|
// process.env.NODE_ENV === 'production'
|
|
// ? {
|
|
// workflowBundle: {
|
|
// // code: workflows
|
|
// codePath: '/app/temporal-workflows/dist/workflows.js'
|
|
// }
|
|
// }
|
|
// : { workflowsPath: require.resolve(workflowsPath) }
|
|
|
|
// Step 1: Register Workflows and Activities with the Worker and connect to
|
|
// the Temporal server.
|
|
const worker = await Worker.create({
|
|
// ...workflowOption(),
|
|
workflowsPath,
|
|
activities,
|
|
taskQueue: process.env.TEMPORAL_TASK_QUEUE!,
|
|
});
|
|
// Worker connects to localhost by default and uses console.error for logging.
|
|
// Customize the Worker by passing more options to create():
|
|
// https://typescript.temporal.io/api/classes/worker.Worker
|
|
|
|
// If you need to configure server connection parameters, see the mTLS example:
|
|
// https://github.com/temporalio/samples-typescript/tree/main/hello-world-mtls
|
|
|
|
// Step 2: Start accepting tasks on the `futureporn` queue
|
|
await worker.run();
|
|
|
|
// You may create multiple Workers in a single process in order to poll on multiple task queues.
|
|
}
|
|
|
|
run().catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|