Files
triggerdotdev--trigger.dev/apps/webapp/app/services/executions/createExecutionEvent.server.ts
Eric Allam 6ebd435e81 Feature: Run execution concurrency limits (#750)
* WIP execution concurrency controls implemented via Redis

- Split up resuming a run and executing a run
- Added some new statuses to better show what is going on in a run
- Removed preprocessing runs

* WIP

* Convert to using ZSETs and adding env vars

* Removed unused import

* Improve run number generation using advistory locks, and only on start

* More execution concurrency stuff

* Add support for job concurrency limits and concurrency limit groups

* Create wild-swans-battle.md

* Increase slots refresh timeout to 10s

* Try to fix Redis connection issues

* Don’t be so strict about the APP_ENV

* Add the blank tls option to the normal redis client as well

* Add docs
2023-11-28 16:21:06 +00:00

58 lines
1.5 KiB
TypeScript

import { PrismaClientOrTransaction, prisma } from "~/db.server";
import { logger } from "../logger.server";
export type CreateExecutionEventInput = {
organizationId: string;
projectId: string;
environmentId: string;
jobId: string;
runId: string;
eventTime: Date;
eventType: "start" | "finish";
drift?: number;
concurrencyLimitGroupId?: string | null;
};
export class CreateExecutionEventService {
constructor(private prismaClient: PrismaClientOrTransaction = prisma) {}
public async call(input: CreateExecutionEventInput) {
await this.prismaClient.$executeRaw`
INSERT INTO "triggerdotdev_events"."run_executions" (
"organization_id",
"project_id",
"environment_id",
"job_id",
"run_id",
"event_time",
"event_type",
"drift_amount_in_ms",
"concurrency_limit_group_id"
) VALUES (
${input.organizationId},
${input.projectId},
${input.environmentId},
${input.jobId},
${input.runId},
${input.eventTime},
${input.eventType === "start" ? 1 : -1},
${input.drift},
${input.concurrencyLimitGroupId}
)
`;
}
}
export async function createExecutionEvent(
input: CreateExecutionEventInput,
options?: { prismaClient?: PrismaClientOrTransaction }
) {
const service = new CreateExecutionEventService(options?.prismaClient);
try {
return await service.call(input);
} catch (error) {
logger.error("Error creating execution event", { error });
}
}