Skip to content

Commit df845e1

Browse files
committed
replace all run engine find uniques with find first
1 parent 2d0bef9 commit df845e1

File tree

5 files changed

+15
-24
lines changed

5 files changed

+15
-24
lines changed

internal-packages/run-engine/src/engine/db/worker.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,10 @@ export async function getManagedWorkerFromCurrentlyPromotedDeployment(
264264
prisma: PrismaClientOrTransaction,
265265
environmentId: string
266266
): Promise<WorkerDeploymentWithWorkerTasks | null> {
267-
// TODO: fixme
268-
const promotion = await prisma.workerDeploymentPromotion.findUnique({
267+
const promotion = await prisma.workerDeploymentPromotion.findFirst({
269268
where: {
270-
environmentId_label: {
271-
environmentId,
272-
label: CURRENT_DEPLOYMENT_LABEL,
273-
},
269+
environmentId,
270+
label: CURRENT_DEPLOYMENT_LABEL,
274271
},
275272
include: {
276273
deployment: {

internal-packages/run-engine/src/engine/systems/batchSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class BatchSystem {
3434
*/
3535
async #tryCompleteBatch({ batchId }: { batchId: string }) {
3636
return startSpan(this.$.tracer, "#tryCompleteBatch", async (span) => {
37-
const batch = await this.$.prisma.batchTaskRun.findUnique({
37+
const batch = await this.$.prisma.batchTaskRun.findFirst({
3838
select: {
3939
status: true,
4040
runtimeEnvironmentId: true,

internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,10 @@ export class RunAttemptSystem {
139139
throw new ServiceValidationError("Task run is not locked", 400);
140140
}
141141

142-
const queue = await prisma.taskQueue.findUnique({
142+
const queue = await prisma.taskQueue.findFirst({
143143
where: {
144-
runtimeEnvironmentId_name: {
145-
runtimeEnvironmentId: environment.id,
146-
name: taskRun.queue,
147-
},
144+
runtimeEnvironmentId: environment.id,
145+
name: taskRun.queue,
148146
},
149147
});
150148

@@ -1199,7 +1197,7 @@ export class RunAttemptSystem {
11991197

12001198
async #getAuthenticatedEnvironmentFromRun(runId: string, tx?: PrismaClientOrTransaction) {
12011199
const prisma = tx ?? this.$.prisma;
1202-
const taskRun = await prisma.taskRun.findUnique({
1200+
const taskRun = await prisma.taskRun.findFirst({
12031201
where: {
12041202
id: runId,
12051203
},

internal-packages/run-engine/src/engine/systems/ttlSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class TtlSystem {
3333
}
3434

3535
//only expire "PENDING" runs
36-
const run = await prisma.taskRun.findUnique({ where: { id: runId } });
36+
const run = await prisma.taskRun.findFirst({ where: { id: runId } });
3737

3838
if (!run) {
3939
this.$.logger.debug("Could not find enqueued run to expire", {

internal-packages/run-engine/src/engine/systems/waitpointSystem.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,10 @@ export class WaitpointSystem {
159159
const prisma = tx ?? this.$.prisma;
160160

161161
const existingWaitpoint = idempotencyKey
162-
? await prisma.waitpoint.findUnique({
162+
? await prisma.waitpoint.findFirst({
163163
where: {
164-
environmentId_idempotencyKey: {
165-
environmentId,
166-
idempotencyKey,
167-
},
164+
environmentId,
165+
idempotencyKey,
168166
},
169167
})
170168
: undefined;
@@ -241,12 +239,10 @@ export class WaitpointSystem {
241239
tags?: string[];
242240
}): Promise<{ waitpoint: Waitpoint; isCached: boolean }> {
243241
const existingWaitpoint = idempotencyKey
244-
? await this.$.prisma.waitpoint.findUnique({
242+
? await this.$.prisma.waitpoint.findFirst({
245243
where: {
246-
environmentId_idempotencyKey: {
247-
environmentId,
248-
idempotencyKey,
249-
},
244+
environmentId,
245+
idempotencyKey,
250246
},
251247
})
252248
: undefined;

0 commit comments

Comments
 (0)