Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apps/webapp/app/presenters/v3/RunPresenter.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ export class RunPresenter {
public async call({
userId,
projectSlug,
organizationSlug,
environmentSlug,
runFriendlyId,
showDeletedLogs,
showDebug,
}: {
userId: string;
projectSlug: string;
organizationSlug: string;
environmentSlug: string;
runFriendlyId: string;
showDeletedLogs: boolean;
Expand Down Expand Up @@ -93,6 +91,13 @@ export class RunPresenter {
friendlyId: runFriendlyId,
project: {
slug: projectSlug,
organization: {
members: {
some: {
userId,
},
},
},
},
},
});
Expand Down
49 changes: 27 additions & 22 deletions apps/webapp/app/presenters/v3/SpanPresenter.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,26 @@ type GetSpanResult = NonNullable<Awaited<ReturnType<(typeof eventRepository)["ge

export class SpanPresenter extends BasePresenter {
public async call({
userId,
projectSlug,
spanId,
runFriendlyId,
}: {
userId: string;
projectSlug: string;
spanId: string;
runFriendlyId: string;
}) {
const project = await this._replica.project.findFirst({
where: {
slug: projectSlug,
organization: {
members: {
some: {
userId,
},
},
},
},
});

Expand All @@ -57,20 +66,19 @@ export class SpanPresenter extends BasePresenter {
},
where: {
friendlyId: runFriendlyId,
projectId: project.id,
},
});

if (!parentRun) {
return;
}

const { traceId } = parentRun;

const eventStore = getTaskEventStoreTableForRun(parentRun);

const run = await this.getRun({
eventStore,
traceId,
environmentId: parentRun.runtimeEnvironmentId,
spanId,
createdAt: parentRun.createdAt,
completedAt: parentRun.completedAt,
Expand All @@ -82,10 +90,8 @@ export class SpanPresenter extends BasePresenter {
};
}

//get the run
const span = await this.#getSpan({
eventStore,
traceId,
spanId,
environmentId: parentRun.runtimeEnvironmentId,
projectId: parentRun.projectId,
Expand All @@ -105,24 +111,24 @@ export class SpanPresenter extends BasePresenter {

async getRun({
eventStore,
traceId,
environmentId,
spanId,
createdAt,
completedAt,
}: {
eventStore: TaskEventStoreTable;
traceId: string;
environmentId: string;
spanId: string;
createdAt: Date;
completedAt: Date | null;
}) {
const span = await eventRepository.getSpan(
eventStore,
const span = await eventRepository.getSpan({
storeTable: eventStore,
spanId,
traceId,
createdAt,
completedAt ?? undefined
);
environmentId,
startCreatedAt: createdAt,
endCreatedAt: completedAt ?? undefined,
});

if (!span) {
return;
Expand Down Expand Up @@ -412,29 +418,28 @@ export class SpanPresenter extends BasePresenter {

async #getSpan({
eventStore,
traceId,
spanId,
environmentId,
projectId,
createdAt,
completedAt,
}: {
traceId: string;
spanId: string;
environmentId: string;
projectId: string;
eventStore: TaskEventStoreTable;
createdAt: Date;
completedAt: Date | null;
}) {
const span = await eventRepository.getSpan(
eventStore,
const span = await eventRepository.getSpan({
storeTable: eventStore,
spanId,
traceId,
createdAt,
completedAt ?? undefined,
{ includeDebugLogs: true }
);
environmentId,
startCreatedAt: createdAt,
endCreatedAt: completedAt ?? undefined,
options: { includeDebugLogs: true },
});

if (!span) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
const [error, result] = await tryCatch(
presenter.call({
userId,
organizationSlug,
showDeletedLogs: !!impersonationId,
projectSlug: projectParam,
runFriendlyId: runParam,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@ import { type LoaderFunctionArgs } from "@remix-run/server-runtime";
import { z } from "zod";
import { prisma } from "~/db.server";
import { requireUserId } from "~/services/session.server";
import { ProjectParamSchema, v3DeploymentPath, v3RunPath } from "~/utils/pathBuilder";
import { ProjectParamSchema, v3RunPath } from "~/utils/pathBuilder";

const ParamSchema = ProjectParamSchema.extend({
runParam: z.string(),
});

export const loader = async ({ request, params }: LoaderFunctionArgs) => {
await requireUserId(request);
const userId = await requireUserId(request);
const { organizationSlug, projectParam, runParam } = ParamSchema.parse(params);

const run = await prisma.taskRun.findFirst({
where: {
friendlyId: runParam,
project: {
slug: projectParam,
organization: {
members: {
some: {
userId,
},
},
},
},
},
select: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ import {
} from "~/utils/pathBuilder";
import { createTimelineSpanEventsFromSpanEvents } from "~/utils/timelineSpanEvents";
import { CompleteWaitpointForm } from "../resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.waitpoints.$waitpointFriendlyId.complete/route";
import { requireUserId } from "~/services/session.server";

export const loader = async ({ request, params }: LoaderFunctionArgs) => {
const userId = await requireUserId(request);
const { projectParam, organizationSlug, envParam, runParam, spanParam } =
v3SpanParamsSchema.parse(params);

Expand All @@ -90,6 +92,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
projectSlug: projectParam,
spanId: spanParam,
runFriendlyId: runParam,
userId,
});

return typedjson(result);
Expand Down
15 changes: 13 additions & 2 deletions apps/webapp/app/routes/resources.taskruns.$runParam.cancel.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { parse } from "@conform-to/zod";
import { ActionFunction, json } from "@remix-run/node";
import { type ActionFunction, json } from "@remix-run/node";
import { z } from "zod";
import { prisma } from "~/db.server";
import { redirectWithErrorMessage, redirectWithSuccessMessage } from "~/models/message.server";
import { logger } from "~/services/logger.server";
import { requireUserId } from "~/services/session.server";
import { CancelTaskRunService } from "~/v3/services/cancelTaskRun.server";

export const cancelSchema = z.object({
Expand All @@ -15,6 +16,7 @@ const ParamSchema = z.object({
});

export const action: ActionFunction = async ({ request, params }) => {
const userId = await requireUserId(request);
const { runParam } = ParamSchema.parse(params);

const formData = await request.formData();
Expand All @@ -25,9 +27,18 @@ export const action: ActionFunction = async ({ request, params }) => {
}

try {
const taskRun = await prisma.taskRun.findUnique({
const taskRun = await prisma.taskRun.findFirst({
where: {
friendlyId: runParam,
project: {
organization: {
members: {
some: {
userId,
},
},
},
},
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LoaderFunctionArgs } from "@remix-run/node";
import { type LoaderFunctionArgs } from "@remix-run/node";
import { typedjson } from "remix-typedjson";
import { z } from "zod";
import { $replica } from "~/db.server";
Expand Down
72 changes: 44 additions & 28 deletions apps/webapp/app/v3/eventRepository.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -970,22 +970,30 @@ export class EventRepository {

// A Span can be cancelled if it is partial and has a parent that is cancelled
// And a span's duration, if it is partial and has a cancelled parent, is the time between the start of the span and the time of the cancellation event of the parent
public async getSpan(
storeTable: TaskEventStoreTable,
spanId: string,
traceId: string,
startCreatedAt: Date,
endCreatedAt?: Date,
options?: { includeDebugLogs?: boolean }
) {
return await startActiveSpan("getSpan", async (s) => {
const spanEvent = await this.#getSpanEvent(
public async getSpan({
storeTable,
spanId,
environmentId,
startCreatedAt,
endCreatedAt,
options,
}: {
storeTable: TaskEventStoreTable;
spanId: string;
environmentId: string;
startCreatedAt: Date;
endCreatedAt?: Date;
options?: { includeDebugLogs?: boolean };
}) {
return await startActiveSpan("getSpan", async () => {
const spanEvent = await this.#getSpanEvent({
storeTable,
spanId,
environmentId,
startCreatedAt,
endCreatedAt,
options
);
options,
});

if (!spanEvent) {
return;
Expand Down Expand Up @@ -1195,12 +1203,12 @@ export class EventRepository {
}

await startActiveSpan("walkSpanAncestors", async (s) => {
let parentEvent = await this.#getSpanEvent(
let parentEvent = await this.#getSpanEvent({
storeTable,
parentId,
spanId: parentId,
startCreatedAt,
endCreatedAt
);
endCreatedAt,
});
let level = 1;

while (parentEvent) {
Expand All @@ -1216,29 +1224,37 @@ export class EventRepository {
return;
}

parentEvent = await this.#getSpanEvent(
parentEvent = await this.#getSpanEvent({
storeTable,
preparedParentEvent.parentId,
spanId: preparedParentEvent.parentId,
startCreatedAt,
endCreatedAt
);
endCreatedAt,
});

level++;
}
});
}

async #getSpanEvent(
storeTable: TaskEventStoreTable,
spanId: string,
startCreatedAt: Date,
endCreatedAt?: Date,
options?: { includeDebugLogs?: boolean }
) {
async #getSpanEvent({
storeTable,
spanId,
environmentId,
startCreatedAt,
endCreatedAt,
options,
}: {
storeTable: TaskEventStoreTable;
spanId: string;
environmentId?: string;
startCreatedAt: Date;
endCreatedAt?: Date;
options?: { includeDebugLogs?: boolean };
}) {
return await startActiveSpan("getSpanEvent", async (s) => {
const events = await this.taskEventStore.findMany(
storeTable,
{ spanId },
{ spanId, ...(environmentId ? { environmentId } : {}) },
startCreatedAt,
endCreatedAt,
undefined,
Expand Down
Loading