fp/packages/temporal-worker/worker.ts

52 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-07-10 02:34:23 +00:00
import { Worker } from '@temporalio/worker';
2024-07-14 05:20:35 +00:00
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');
2024-07-10 02:34:23 +00:00
async function run() {
2024-07-14 05:20:35 +00:00
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) }
2024-07-10 02:34:23 +00:00
// Step 1: Register Workflows and Activities with the Worker and connect to
// the Temporal server.
const worker = await Worker.create({
2024-07-14 05:20:35 +00:00
// ...workflowOption(),
workflowsPath,
2024-07-10 02:34:23 +00:00
activities,
2024-07-14 05:20:35 +00:00
taskQueue: process.env.TEMPORAL_TASK_QUEUE!,
2024-07-10 02:34:23 +00:00
});
// 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);
});