Skip to main content

Introduction to Workers

Workers execute the tasks defined in your Workflows and Activities. With your Activity and Workflow code defined, you need a Worker to execute it.

A Worker polls a queue that you configure it to poll, looking for work to do. This queue is known as a Task Queue. Once the Worker dequeues a Workflow or Activity task from the Task Queue, it then executes that task.

The Worker itself is provided by the Temporal SDK, and your application configures and runs it. Workers communicate with Temporal to coordinate work, while your code continues to be executed by Workers that you own.

This Worker is configured to execute your Workflow and Activity tasks dispatched to the reimbursement-queue.

Workflow Code
import {Worker} from '@temporalio/worker';
import * as activities from './activities';

async function run() {
const worker = await Worker.create({
workflowsPath: require.resolve('./workflows'),
activities,
taskQueue: 'reimbursement-queue', //Worker is polling this task queue looking for tasks to be done
});
await worker.run();
}
run().catch((err) => {
console.error(err);
process.exit(1);
});
4 / 10