Implement public audit pages
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { api, internal } from "./_generated/api";
|
||||
import { internalAction } from "./_generated/server";
|
||||
import type { Id } from "./_generated/dataModel";
|
||||
import type { ActionCtx } from "./_generated/server";
|
||||
import { v } from "convex/values";
|
||||
import {
|
||||
classifyPageSpeedError,
|
||||
@@ -101,6 +102,44 @@ function classifyPageSpeedFailure(input: unknown, apiKey?: string | null) {
|
||||
};
|
||||
}
|
||||
|
||||
type StartedPageSpeedAudit = {
|
||||
lead: {
|
||||
_id: Id<"leads">;
|
||||
websiteUrl: string;
|
||||
};
|
||||
auditId?: Id<"audits">;
|
||||
};
|
||||
|
||||
async function queueAuditGenerationAfterPageSpeed(
|
||||
ctx: ActionCtx,
|
||||
runId: Id<"agentRuns">,
|
||||
started: StartedPageSpeedAudit,
|
||||
) {
|
||||
try {
|
||||
await ctx.runMutation(internal.auditGeneration.queueLeadAuditGeneration, {
|
||||
leadId: started.lead._id,
|
||||
...(started.auditId ? { auditId: started.auditId } : {}),
|
||||
parentRunId: runId,
|
||||
});
|
||||
} catch (auditQueueError) {
|
||||
await ctx.runMutation(api.runs.appendEvent, {
|
||||
runId,
|
||||
level: "warning",
|
||||
message: "Audit-Generierung konnte nicht in die Warteschlange gesetzt werden.",
|
||||
details: [
|
||||
{ label: "Lead", value: started.lead._id },
|
||||
{
|
||||
label: "Fehler",
|
||||
value: auditQueueError instanceof Error
|
||||
? auditQueueError.message
|
||||
: String(auditQueueError),
|
||||
source: "audit_generation_queue",
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const processPageSpeedAudit = internalAction({
|
||||
args: {
|
||||
runId: v.id("agentRuns"),
|
||||
@@ -109,15 +148,7 @@ export const processPageSpeedAudit = internalAction({
|
||||
const apiKeyRaw = process.env.PAGESPEED_API_KEY?.trim();
|
||||
const apiKey = apiKeyRaw ? apiKeyRaw : undefined;
|
||||
|
||||
let started:
|
||||
| {
|
||||
lead: {
|
||||
_id: Id<"leads">;
|
||||
websiteUrl: string;
|
||||
};
|
||||
auditId?: Id<"audits">;
|
||||
}
|
||||
| null = null;
|
||||
let started: StartedPageSpeedAudit | null = null;
|
||||
|
||||
try {
|
||||
started = await ctx.runMutation(internal.pageSpeed.startPageSpeedAuditRun, {
|
||||
@@ -267,6 +298,8 @@ export const processPageSpeedAudit = internalAction({
|
||||
: undefined,
|
||||
});
|
||||
|
||||
await queueAuditGenerationAfterPageSpeed(ctx, args.runId, started);
|
||||
|
||||
return args.runId;
|
||||
} catch (error) {
|
||||
const { errorSummary } = classifyPageSpeedFailure(error, apiKeyRaw);
|
||||
@@ -283,6 +316,7 @@ export const processPageSpeedAudit = internalAction({
|
||||
message: "PageSpeed-Analyse fehlgeschlagen.",
|
||||
details: [{ label: "Fehler", value: errorSummary, source: "pagespeed_action" }],
|
||||
});
|
||||
await queueAuditGenerationAfterPageSpeed(ctx, args.runId, started);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user