fae93ac747
* Fix for “overridden” spelling mistake * Make the task function names grey instead of yellow * The task page now shows each task once * Blankline * WIP on activity bars * Correct size of the graphs * Add data for all days, even if there are no runs * Activity graph is working and has a tooltip * No activity label * Got the bar bg working * Activity chart now has a bg * Added a compound id to make the activity graphs appear faster * Improvements to the activity graph * Tried to disable the bg from animating * Added read replica support to the app, using Nick’s code from his batching PR * Added the read replica to BasePresenter * Added the queued and running columns to the Tasks list * Added avg duration column * Included completed but failed runs in the average duration * Get rid of the old useDevEnvironment hook and remove API keys from the projects query * Unified getting environment info to using a function and doing it in presenters * Removed the path from the tasks table * Onboarding for dev for 2nd+ user. Improved environment sorting. * Removed log * Improved the spacing * Enable staging for new v3 projects
155 lines
3.2 KiB
TypeScript
155 lines
3.2 KiB
TypeScript
import type { Prisma, RuntimeEnvironment } from "@trigger.dev/database";
|
|
import { prisma } from "~/db.server";
|
|
import { getUsername } from "~/utils/username";
|
|
|
|
export type { RuntimeEnvironment };
|
|
|
|
export async function findEnvironmentByApiKey(apiKey: string) {
|
|
const environment = await prisma.runtimeEnvironment.findUnique({
|
|
where: {
|
|
apiKey,
|
|
},
|
|
include: {
|
|
project: true,
|
|
organization: true,
|
|
orgMember: true,
|
|
},
|
|
});
|
|
|
|
//don't return deleted projects
|
|
if (environment?.project.deletedAt !== null) {
|
|
return null;
|
|
}
|
|
|
|
return environment;
|
|
}
|
|
|
|
export async function findEnvironmentByPublicApiKey(apiKey: string) {
|
|
const environment = await prisma.runtimeEnvironment.findUnique({
|
|
where: {
|
|
pkApiKey: apiKey,
|
|
},
|
|
include: {
|
|
project: true,
|
|
organization: true,
|
|
orgMember: true,
|
|
},
|
|
});
|
|
|
|
//don't return deleted projects
|
|
if (environment?.project.deletedAt !== null) {
|
|
return null;
|
|
}
|
|
|
|
return environment;
|
|
}
|
|
|
|
export async function findEnvironmentById(id: string) {
|
|
const environment = await prisma.runtimeEnvironment.findUnique({
|
|
where: {
|
|
id,
|
|
},
|
|
include: {
|
|
project: true,
|
|
organization: true,
|
|
orgMember: true,
|
|
},
|
|
});
|
|
|
|
//don't return deleted projects
|
|
if (environment?.project.deletedAt !== null) {
|
|
return null;
|
|
}
|
|
|
|
return environment;
|
|
}
|
|
|
|
export async function createNewSession(environment: RuntimeEnvironment, ipAddress: string) {
|
|
return prisma.$transaction(async (tx) => {
|
|
const session = await tx.runtimeEnvironmentSession.create({
|
|
data: {
|
|
environmentId: environment.id,
|
|
ipAddress,
|
|
},
|
|
});
|
|
|
|
await tx.runtimeEnvironment.update({
|
|
where: {
|
|
id: environment.id,
|
|
},
|
|
data: {
|
|
currentSessionId: session.id,
|
|
},
|
|
});
|
|
|
|
return session;
|
|
});
|
|
}
|
|
|
|
export async function disconnectSession(environmentId: string) {
|
|
return prisma.$transaction(async (tx) => {
|
|
const environment = await tx.runtimeEnvironment.findUnique({
|
|
where: {
|
|
id: environmentId,
|
|
},
|
|
});
|
|
|
|
if (!environment || !environment.currentSessionId) {
|
|
return null;
|
|
}
|
|
|
|
const session = await tx.runtimeEnvironmentSession.update({
|
|
where: {
|
|
id: environment.currentSessionId,
|
|
},
|
|
data: {
|
|
disconnectedAt: new Date(),
|
|
},
|
|
});
|
|
|
|
await tx.runtimeEnvironment.update({
|
|
where: {
|
|
id: environment.id,
|
|
},
|
|
data: {
|
|
currentSessionId: null,
|
|
},
|
|
});
|
|
|
|
return session;
|
|
});
|
|
}
|
|
|
|
type DisplayableInputEnvironment = Prisma.RuntimeEnvironmentGetPayload<{
|
|
select: {
|
|
id: true;
|
|
type: true;
|
|
orgMember: {
|
|
select: {
|
|
user: {
|
|
select: {
|
|
id: true;
|
|
name: true;
|
|
displayName: true;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}>;
|
|
|
|
export function displayableEnvironments(
|
|
environment: DisplayableInputEnvironment,
|
|
userId: string | undefined
|
|
) {
|
|
return {
|
|
id: environment.id,
|
|
type: environment.type,
|
|
userName: environment.orgMember
|
|
? environment.orgMember.user.id === userId
|
|
? undefined
|
|
: getUsername(environment.orgMember.user)
|
|
: undefined,
|
|
};
|
|
}
|