Worker execution in the Trigger.dev platform refers to the background job processing system that handles asynchronous platform operations. This page documents the ZodWorker system, the workerCatalog that defines available background jobs, the handler functions that process these jobs, and the migration from a monolithic worker file to specialized worker modules.
This system is distinct from task execution workers (which run user-defined task code). Background workers handle internal platform operations like sending emails, processing alerts, retrying failed attempts, and managing deployments.
For information about task execution in user code, see sections on the Run Engine. For information about queue management, see Queue Management.
Sources: apps/webapp/app/services/worker.server.ts1-346
The background worker system uses ZodWorker, a wrapper around Graphile Worker that provides type-safe job definitions with Zod schemas. Jobs are enqueued from service classes throughout the application and processed asynchronously by worker handlers.
ZodWorker is a type-safe wrapper around Graphile Worker that provides schema validation, job registration, and execution management. It is defined in the internal packages and used by the webapp to process background jobs.
Sources: apps/webapp/app/services/worker.server.ts133-148
Configuration Options:
name: Identifier for the worker instanceprisma / replica: Database clients for job persistencerunnerOptions: Graphile Worker configuration (connection, concurrency, polling)logger: Structured logging instanceshutdownTimeoutInMs: Grace period for completing jobs on shutdownschema: workerCatalog defining job payload schemasrecurringTasks: Cron-style scheduled jobstasks: Handler functions for each job typeSources: apps/webapp/app/services/worker.server.ts105-122
In development, the worker is cached in a global variable to prevent recreation on hot reload. In production, a new instance is created at startup.
Sources: apps/webapp/app/services/worker.server.ts124-131
The init() function runs Graphile Worker schema migrations and starts the worker if WORKER_ENABLED is set. This allows running the webapp with workers disabled.
The workerCatalog defines all available background job types with Zod schemas for type-safe payload validation. It maps job identifiers to their payload schemas.
Sources: apps/webapp/app/services/worker.server.ts33-103
Key Characteristics:
"v3.retryAttempt")@deprecated with migration notesJob identifiers follow patterns:
scheduleEmail: Legacy email deliveryv3.*: Version 3 platform operationsrunengine.*: Run engine specific operationsperformTaskRunAlerts, enqueueDelayedRunSources: apps/webapp/app/services/worker.server.ts33-103
Job handlers are registered in the tasks configuration of ZodWorker. Each handler specifies priority, retry attempts, and the execution function.
Sources: apps/webapp/app/services/worker.server.ts158-176
Handler Properties:
priority: Integer for job ordering (lower = higher priority)maxAttempts: Number of retry attempts before permanent failurehandler: Async function receiving validated payload and job metadataSources: apps/webapp/app/services/worker.server.ts158-342
Most handlers follow the pattern:
Email Delivery:
Retry Attempt:
Batch Processing:
Sources: apps/webapp/app/services/worker.server.ts160-166 apps/webapp/app/services/worker.server.ts273-281 apps/webapp/app/services/worker.server.ts323-331
Sources: apps/webapp/app/services/worker.server.ts158-342
Handlers receive:
workerCatalogattempts, max_attempts, job ID, and other metadataThe handler can:
maxAttempts)job.attemptsZodWorker supports recurring tasks that run on cron-style schedules for periodic maintenance operations.
Sources: apps/webapp/app/services/worker.server.ts149-157
The concurrency monitor runs every 5 minutes to check and manage queue concurrency limits. It uses the MarqsConcurrencyMonitor service to monitor V3 queues.
Recurring Task Configuration:
match: Cron expression for scheduling (format: minute hour day month dayOfWeek)handler: Function that executes on schedulehelpers: Provides abortSignal for graceful cancellationThis pattern allows background maintenance tasks to run automatically without manual triggering.
Sources: apps/webapp/app/services/worker.server.ts149-157
The codebase is undergoing a migration from a monolithic worker.server.ts to specialized worker files. This improves code organization and allows independent scaling of worker types.
Sources: apps/webapp/app/services/worker.server.ts34-103
Throughout worker.server.ts, jobs are marked with deprecation comments indicating their new location:
Sources: apps/webapp/app/services/worker.server.ts34-77
| Job Category | Destination | Purpose |
|---|---|---|
| Email delivery | commonWorker.server.ts | Common platform operations |
| Alert operations | alertsWorker.server.ts | Alert delivery and processing |
| Scheduled task triggers | ScheduleEngine | Cron-based task triggering |
| Legacy run operations | legacyRunEngineWorker.server.ts | V1 run engine operations |
| Task dependencies | commonWorker.server.ts | Dependency resolution |
| Batch processing | commonWorker.server.ts | Batch task operations |
| Deployment operations | commonWorker.server.ts | Deployment lifecycle |
Sources: apps/webapp/app/services/worker.server.ts34-103
Some jobs remain in worker.server.ts:
Bulk Actions:
Batch Run Resume (used in transactions):
Batch Processing:
Sources: apps/webapp/app/services/worker.server.ts37-39 apps/webapp/app/services/worker.server.ts71-76 apps/webapp/app/services/worker.server.ts100-103
Code Organization:
Operational Benefits:
Development Benefits:
Sources: apps/webapp/app/services/worker.server.ts133-343
Sources: apps/webapp/app/services/worker.server.ts158-342
Jobs progress through states managed by Graphile Worker:
Sources: apps/webapp/app/services/worker.server.ts273-291
Priority System:
Retry Configuration:
maxAttempts varies by job criticalityWorker execution in Trigger.dev involves multiple coordinated layers:
dev-run-worker.ts) and production (managed-run-worker.ts) with different resource trackingThe architecture provides isolation, observability, and flexibility while supporting both rapid development iteration and production reliability.
Sources: packages/core/src/v3/workers/taskExecutor.ts66-1370 packages/cli-v3/src/entryPoints/dev-run-worker.ts1-735 packages/cli-v3/src/entryPoints/managed-run-worker.ts1-559 packages/cli-v3/src/executions/taskRunProcess.ts64-518 packages/cli-v3/src/dev/taskRunProcessPool.ts20-349
Refresh this wiki