Files
triggerdotdev--trigger.dev/apps/webapp/app/v3/scheduleEngine.server.ts
Eric Allam 5ba8557a51 chore(webapp,core): remove the end-of-life v3 (engine V1) execution stack (#4236)
## Summary

v3 (the engine that ran the SDK v3 era, internally
`RunEngineVersion.V1`) is end-of-life. Following the removal of the v3
execution apps
([#4194](https://github.com/triggerdotdev/trigger.dev/pull/4194)) and
the legacy dev websocket
([#4198](https://github.com/triggerdotdev/trigger.dev/pull/4198)), this
removes the remaining v3 execution stack from the server.

Clients still on v3 (an old SDK or CLI that has not upgraded) keep
getting a clear "upgrade to v4" response. Triggers, batch triggers,
reschedules, and deploys that resolve to v3 are rejected with a graceful
4xx pointing at the migration guide, never a 5xx, so a stale client
cannot affect server health. Self-hosted instances still running v3
should stay on the 4.5.x release line until they migrate.

## What is removed

- The MarQS queue and its shared/dev queue consumers.
- The v3 socket.io namespaces (coordinator, provider, shared-queue) and
the v3 run lifecycle services (attempt, checkpoint, and batch-resume).
- The graphile-worker background job system; all live jobs already run
on `@trigger.dev/redis-worker`.
- The `DEPRECATE_V3_ENABLED` flag: v3 is now rejected unconditionally,
so the flag is gone.
- Unused v3 exports from `@trigger.dev/core` (the `v3/zodNamespace`
subpath and the legacy socket message catalogs) and the now-dead MarQS
environment variables.

## What stays

The v4 engine is untouched. The graceful v3 rejection boundary stays,
`determineEngineVersion` still detects a v3 project so it can reject it,
and the batch service plus batch-completion worker stay for current
clients. Live queue concurrency limits and metrics now read from the v4
run engine instead of MarQS, and a brand-new dev environment now
defaults to v4.



## Dependency cleanup

Removes webapp dependencies left unused by this change: `seedrandom` and
`semver` (only the removed v3 code used them) plus a set that was
already dead, their orphaned `@types` packages, and two dead files. Adds
a `knip:deps` script and a `knip.json` config so unused dependencies can
be found the same way going forward.
2026-07-13 11:32:06 +01:00

153 lines
4.8 KiB
TypeScript

import { ScheduleEngine } from "@internal/schedule-engine";
import type { TriggerScheduledTaskErrorType } from "@internal/schedule-engine";
import { stringifyIO } from "@trigger.dev/core/v3";
import { prisma } from "~/db.server";
import { env } from "~/env.server";
import { devPresence } from "~/presenters/v3/DevPresence.server";
import { logger } from "~/services/logger.server";
import { singleton } from "~/utils/singleton";
import { OutOfEntitlementError, TriggerTaskService } from "./services/triggerTask.server";
import { meter, tracer } from "./tracer.server";
import { ServiceValidationError } from "./services/common.server";
export const scheduleEngine = singleton("ScheduleEngine", createScheduleEngine);
export type { ScheduleEngine };
async function isDevEnvironmentConnectedHandler(environmentId: string) {
const environment = await prisma.runtimeEnvironment.findFirst({
where: {
id: environmentId,
},
select: {
currentSession: {
select: {
disconnectedAt: true,
},
},
project: {
select: {
engine: true,
},
},
},
});
if (!environment) {
return false;
}
if (environment.project.engine === "V1") {
const v3Disconnected = !environment.currentSession || environment.currentSession.disconnectedAt;
return !v3Disconnected;
}
const v4Connected = await devPresence.isConnected(environmentId);
return v4Connected;
}
function createScheduleEngine() {
const engine = new ScheduleEngine({
prisma,
logLevel: env.SCHEDULE_ENGINE_LOG_LEVEL,
redis: {
host: env.SCHEDULE_WORKER_REDIS_HOST ?? "localhost",
port: env.SCHEDULE_WORKER_REDIS_PORT ?? 6379,
username: env.SCHEDULE_WORKER_REDIS_USERNAME,
password: env.SCHEDULE_WORKER_REDIS_PASSWORD,
keyPrefix: "schedule:",
enableAutoPipelining: true,
...(env.SCHEDULE_WORKER_REDIS_TLS_DISABLED === "true" ? {} : { tls: {} }),
},
worker: {
concurrency: env.SCHEDULE_WORKER_CONCURRENCY_LIMIT,
workers: env.SCHEDULE_WORKER_CONCURRENCY_WORKERS,
tasksPerWorker: env.SCHEDULE_WORKER_CONCURRENCY_TASKS_PER_WORKER,
pollIntervalMs: env.SCHEDULE_WORKER_POLL_INTERVAL,
shutdownTimeoutMs: env.SCHEDULE_WORKER_SHUTDOWN_TIMEOUT_MS,
disabled: env.SCHEDULE_WORKER_ENABLED === "0",
},
distributionWindow: {
seconds: env.SCHEDULE_WORKER_DISTRIBUTION_WINDOW_SECONDS,
},
tracer,
meter,
onTriggerScheduledTask: async ({
taskIdentifier,
environment,
payload,
scheduleInstanceId,
scheduleId,
exactScheduleTime,
}) => {
try {
// v3 (engine V1) is retired: skip firing V1 schedules instead of triggering into a guaranteed rejection every tick.
if (environment.project.engine === "V1") {
logger.debug("[ScheduleEngine] Skipping scheduled fire for shut-down v3 project", {
taskIdentifier,
scheduleId,
});
return { success: true };
}
// This will trigger either v1 or v2 depending on the engine of the project
const triggerService = new TriggerTaskService();
const payloadPacket = await stringifyIO(payload);
logger.debug("Triggering scheduled task", {
taskIdentifier,
environment,
payload,
scheduleInstanceId,
scheduleId,
exactScheduleTime,
});
const result = await triggerService.call(
taskIdentifier,
environment,
{ payload: payloadPacket.data, options: { payloadType: payloadPacket.dataType } },
{
customIcon: "scheduled",
scheduleId,
scheduleInstanceId,
queueTimestamp: exactScheduleTime,
overrideCreatedAt: exactScheduleTime,
triggerSource: "schedule",
triggerAction: "trigger",
}
);
return { success: !!result };
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
let errorType: TriggerScheduledTaskErrorType = "SYSTEM_ERROR";
if (
error instanceof ServiceValidationError &&
errorMessage.includes("queue size limit for this environment has been reached")
) {
errorType = "QUEUE_LIMIT";
} else if (error instanceof OutOfEntitlementError) {
// The org is out of entitlements. This is an expected outcome, not a
// system error, so the engine logs it as a warning rather than
// reporting it as an error.
errorType = "OUT_OF_ENTITLEMENTS";
}
return {
success: false,
error: errorMessage,
errorType,
};
}
},
isDevEnvironmentConnectedHandler: isDevEnvironmentConnectedHandler,
});
return engine;
}