1+ /**
2+ * ⚠️ LEGACY — Graphile-worker / ZodWorker setup. Do not touch.
3+ *
4+ * This file wires the original background-job system the webapp was
5+ * built on (`@internal/zod-worker` → graphile-worker → Postgres). It is
6+ * now in deprecation mode: every task in `workerCatalog` below is
7+ * annotated with `@deprecated, moved to <new home>` and the live jobs
8+ * for new features all run on `@trigger.dev/redis-worker` instead.
9+ *
10+ * Where to put new things:
11+ * - Background jobs / queues → use redis-worker, alongside
12+ * `~/v3/commonWorker.server.ts`, `~/v3/alertsWorker.server.ts`, or
13+ * `~/v3/batchTriggerWorker.server.ts`.
14+ * - Run lifecycle → `@internal/run-engine` via `~/v3/runEngine.server`.
15+ * - Custom polling loops with their own Redis connection → keep them
16+ * in their own lifecycle module (e.g. `~/v3/mollifierDrainerWorker.server.ts`)
17+ * and wire the bootstrap from `entry.server.tsx`. Don't reach into
18+ * `init()` below.
19+ *
20+ * Edit only when removing legacy paths.
21+ */
122import { ZodWorker } from "@internal/zod-worker" ;
223import { DeliverEmailSchema } from "emails" ;
324import { z } from "zod" ;
@@ -26,7 +47,6 @@ import { ResumeBatchRunService } from "~/v3/services/resumeBatchRun.server";
2647import { ResumeTaskDependencyService } from "~/v3/services/resumeTaskDependency.server" ;
2748import { RetryAttemptService } from "~/v3/services/retryAttempt.server" ;
2849import { TimeoutDeploymentService } from "~/v3/services/timeoutDeployment.server" ;
29- import { getMollifierDrainer } from "~/v3/mollifier/mollifierDrainer.server" ;
3050import { GraphileMigrationHelperService } from "./db/graphileMigrationHelper.server" ;
3151import { sendEmail } from "./email.server" ;
3252import { logger } from "./logger.server" ;
@@ -107,7 +127,6 @@ let workerQueue: ZodWorker<typeof workerCatalog>;
107127
108128declare global {
109129 var __worker__ : ZodWorker < typeof workerCatalog > ;
110- var __mollifierShutdownRegistered__ : boolean | undefined ;
111130}
112131
113132// this is needed because in development we don't want to restart
@@ -130,55 +149,6 @@ export async function init() {
130149 if ( env . WORKER_ENABLED === "true" ) {
131150 await workerQueue . initialize ( ) ;
132151 }
133-
134- // Only the worker role drains the mollifier buffer. API-only replicas
135- // still produce into the buffer via the trigger hot path, but the
136- // polling loop + Redis consumer connection only belongs on workers —
137- // otherwise every webapp replica races for the same entries.
138- if ( env . WORKER_ENABLED !== "true" ) {
139- return ;
140- }
141-
142- try {
143- // getMollifierDrainer() runs the singleton factory, which validates the
144- // shutdown-timeout reconciliation against GRACEFUL_SHUTDOWN_TIMEOUT and
145- // throws BEFORE constructing the drainer if it's misconfigured. The
146- // outer catch below logs and aborts drainer registration on either that
147- // validation error or a Redis init failure — no half-started state. The
148- // returned drainer is configured-but-stopped; start() runs below, AFTER
149- // the SIGTERM/SIGINT handlers are registered, so a signal landing during
150- // boot can never find the polling loop running without a graceful-stop
151- // path. Same `__mollifierShutdownRegistered__` guard owns both the
152- // handler registration and the start() call so dev hot-reloads don't
153- // double-register or double-start.
154- const drainer = getMollifierDrainer ( ) ;
155- if ( drainer && ! global . __mollifierShutdownRegistered__ ) {
156- // The drainer owns a polling loop and a Redis client; let it drain
157- // in-flight pops on shutdown rather than tearing the process down
158- // mid-handler. `init()` is called per request from entry.server.tsx,
159- // and `process.once()` only removes its listener after it fires — so
160- // without a process-global guard, dev hot-reloads would stack a fresh
161- // listener pair every request. Mirrors the `__worker__` singleton
162- // pattern above.
163- // Bound shutdown so a hung handler can't block process exit past the
164- // pod's termination grace period. `drainer.stop({ timeoutMs })` logs a
165- // warning and returns if the deadline is hit while a handler is still
166- // in flight.
167- const stopDrainer = ( ) => {
168- drainer
169- . stop ( { timeoutMs : env . MOLLIFIER_DRAIN_SHUTDOWN_TIMEOUT_MS } )
170- . catch ( ( error ) => {
171- logger . error ( "Failed to stop mollifier drainer" , { error } ) ;
172- } ) ;
173- } ;
174- process . once ( "SIGTERM" , stopDrainer ) ;
175- process . once ( "SIGINT" , stopDrainer ) ;
176- global . __mollifierShutdownRegistered__ = true ;
177- drainer . start ( ) ;
178- }
179- } catch ( error ) {
180- logger . error ( "Failed to initialise mollifier drainer" , { error } ) ;
181- }
182152}
183153
184154function getWorkerQueue ( ) {
0 commit comments