Files
triggerdotdev--trigger.dev/apps/webapp/app/v3/services/enqueueRun.server.ts
Chris Arderne c7861be520 chore: activate no-unused-vars and import linters (#4096)
Once this is merged, oxlint is at a pretty sensible baseline.

**Enable `no-unused-vars`, `typescript/consistent-type-imports`, and
`import/no-duplicates` lint rules**

Turns on three previously-disabled oxlint rules across the monorepo and
fixes all violations:

- **`no-unused-vars`** – enabled as an error with standard ignore
patterns: unused function arguments are ignored by default (`args:
"none"`), variables/caught errors/destructured array elements prefixed
with `_` are allowed, and rest siblings are permitted.
- **`typescript/consistent-type-imports`** – enforced as an error; all
type-only imports now use the `import type` syntax.
- **`import/no-duplicates`** – enforced as an error; duplicate import
statements from the same module have been merged.

The remaining commits clean up the violations found across the codebase:
removing unused variables/imports/type aliases, adding `_` prefixes to
intentionally unused bindings, fixing duplicate imports, and converting
value imports to `import type` where appropriate.
2026-07-02 11:37:05 +01:00

68 lines
1.9 KiB
TypeScript

import type { TaskRunError } from "@trigger.dev/core/v3/schemas";
import { TaskRunErrorCodes } from "@trigger.dev/core/v3/schemas";
import type { TaskRun } from "@trigger.dev/database";
import type { AuthenticatedEnvironment } from "~/services/apiAuth.server";
import { marqs } from "../marqs/index.server";
export type EnqueueRunOptions = {
env: AuthenticatedEnvironment;
run: TaskRun;
dependentRun?: { queue: string; id: string };
};
export type EnqueueRunResult =
| {
ok: true;
}
| {
ok: false;
error: TaskRunError;
};
export async function enqueueRun({
env,
run,
dependentRun,
}: EnqueueRunOptions): Promise<EnqueueRunResult> {
// If this is a triggerAndWait or batchTriggerAndWait,
// we need to add the parent run to the reserve concurrency set
// to free up concurrency for the children to run
// In the case of a recursive queue, reserving concurrency can fail, which means there is a deadlock and we need to fail the run
// TODO: reserveConcurrency can fail because of a deadlock, we need to handle that case
const wasEnqueued = await marqs.enqueueMessage(
env,
run.queue,
run.id,
{
type: "EXECUTE",
taskIdentifier: run.taskIdentifier,
projectId: env.projectId,
environmentId: env.id,
environmentType: env.type,
},
run.concurrencyKey ?? undefined,
run.queueTimestamp ?? undefined,
dependentRun
? { messageId: dependentRun.id, recursiveQueue: dependentRun.queue === run.queue }
: undefined
);
if (!wasEnqueued) {
const error = {
type: "INTERNAL_ERROR",
code: TaskRunErrorCodes.RECURSIVE_WAIT_DEADLOCK,
message: `This run will never execute because it was triggered recursively and the task has no remaining concurrency available`,
} satisfies TaskRunError;
return {
ok: false,
error,
};
}
return {
ok: true,
};
}