Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): label operator Loom imports as bulk for the importer

Richie McIlroyf24a7612c8bd
diff --git a/apps/web/__tests__/unit/loom-import-start.test.ts b/apps/web/__tests__/unit/loom-import-start.test.ts
index 4af353608..3500d1cb1 100644
--- a/apps/web/__tests__/unit/loom-import-start.test.ts
+++ b/apps/web/__tests__/unit/loom-import-start.test.ts
@@ -188,6 +188,18 @@ describe("Loom workflow startup receipts", () => {
);
});
+ it("keeps an operator import's bulk lane on its startup receipt", async () => {
+ await startLoomImportWorkflow({ ...payload, importPriority: "bulk" });
+ expect(
+ mocks.set.mock.calls.map(([value]) =>
+ JSON.parse(value.metadata.values.at(-1)),
+ ),
+ ).toEqual([
+ { runId: "run-1", dispatch: "pending", importPriority: "bulk" },
+ { runId: "run-1", dispatch: "accepted", importPriority: "bulk" },
+ ]);
+ });
+
it("does not overwrite a newer import startup receipt", async () => {
mocks.where
.mockResolvedValueOnce([{ affectedRows: 1 }])
diff --git a/apps/web/__tests__/unit/loom-importer-redrive.test.ts b/apps/web/__tests__/unit/loom-importer-redrive.test.ts
index 200e38f67..23353582e 100644
--- a/apps/web/__tests__/unit/loom-importer-redrive.test.ts
+++ b/apps/web/__tests__/unit/loom-importer-redrive.test.ts
@@ -142,6 +142,7 @@ describe("redriveLoomImport", () => {
bucketId: "bucket",
loomVideoId: "a".repeat(32),
reuseExistingRawUpload: true,
+ importPriority: "bulk",
});
});
diff --git a/apps/web/__tests__/unit/loom-operator-tools.test.ts b/apps/web/__tests__/unit/loom-operator-tools.test.ts
index 9acf16705..00c2353c3 100644
--- a/apps/web/__tests__/unit/loom-operator-tools.test.ts
+++ b/apps/web/__tests__/unit/loom-operator-tools.test.ts
@@ -247,6 +247,7 @@ describe("operator CSV import", () => {
orgId: ids.org,
actorId: "owneraaaaaaaaaa",
allowFolders: true,
+ importPriority: "bulk",
});
});
diff --git a/apps/web/__tests__/unit/media-processing-workflows.test.ts b/apps/web/__tests__/unit/media-processing-workflows.test.ts
index 5f1546cd8..939f74b20 100644
--- a/apps/web/__tests__/unit/media-processing-workflows.test.ts
+++ b/apps/web/__tests__/unit/media-processing-workflows.test.ts
@@ -248,6 +248,7 @@ describe("media processing workflows", () => {
"https://storage.example.com/owner/video/raw-upload.mp4?upload=1",
priority: "bulk",
});
+ expect(JSON.parse(calls[1]?.[1].body)).not.toHaveProperty("importPriority");
expect(mocks.remove).not.toHaveBeenCalled();
});
@@ -297,6 +298,20 @@ describe("media processing workflows", () => {
expect(body.thumbnailPresignedUrl).toBeDefined();
expect(body.sourcePresignedUrl).toBeUndefined();
expect(body.sourceUpload).toBeUndefined();
+ expect(body.importPriority).toBe("customer");
+ });
+
+ it("keeps operator redrives in the importer's bulk lane", async () => {
+ mocks.loomSourceUrl = "https://luna.loom.com/id/x/playlist.m3u8";
+ mocks.rows = [[video], [], [metadata]];
+ mocks.sleep.mockImplementation(() => new Promise(() => undefined));
+ await expect(
+ importLoomVideoWorkflow({ ...payload, importPriority: "bulk" }),
+ ).resolves.toMatchObject({ success: true });
+ expect(dispatchedBody()).toMatchObject({
+ priority: "bulk",
+ importPriority: "bulk",
+ });
});
it.each([
diff --git a/apps/web/__tests__/unit/video-pipeline-recovery.test.ts b/apps/web/__tests__/unit/video-pipeline-recovery.test.ts
index 561debc48..2cb2c5d95 100644
--- a/apps/web/__tests__/unit/video-pipeline-recovery.test.ts
+++ b/apps/web/__tests__/unit/video-pipeline-recovery.test.ts
@@ -245,7 +245,13 @@ describe("recoverStalledVideoPipeline", () => {
bucketId: null,
rawFileKey: "user-1/video-loom/raw.mp4",
loomVideoId: "loom-video-1",
- metadata: { loomImportRun: { runId: "old-run", dispatch: "accepted" } },
+ metadata: {
+ loomImportRun: {
+ runId: "old-run",
+ dispatch: "accepted",
+ importPriority: "bulk",
+ },
+ },
processingMessage,
updatedAt: staleAt,
};
@@ -273,6 +279,7 @@ describe("recoverStalledVideoPipeline", () => {
videoId: "video-loom",
loomVideoId: "loom-video-1",
reuseExistingRawUpload: true,
+ importPriority: "bulk",
}),
);
expect(mockStart).not.toHaveBeenCalled();
diff --git a/apps/web/__tests__/unit/video-processing-recovery.test.ts b/apps/web/__tests__/unit/video-processing-recovery.test.ts
index b2d59f6fa..9c58b956f 100644
--- a/apps/web/__tests__/unit/video-processing-recovery.test.ts
+++ b/apps/web/__tests__/unit/video-processing-recovery.test.ts
@@ -347,37 +347,54 @@ describe("recoverFailedVideoProcessing", () => {
expect(result.statuses).toEqual({ "retry-scheduled": 1 });
});
- it("restarts a Loom import that exhausted its capacity retries", async () => {
- mockDb
- .mockReturnValueOnce(makeSelectChain([]))
- .mockReturnValueOnce(makeSelectChain([]))
- .mockReturnValueOnce(
- makeSelectChain([
- {
- ...candidate,
- orgId: "organization-1",
- },
- ]),
- )
- .mockReturnValueOnce(makeSelectChain([{ loomVideoId: "loom-video-1" }]))
- .mockReturnValueOnce(makeSelectChain([]))
- .mockReturnValueOnce(makeUpdateChain(1));
- const { recoverFailedVideoProcessing } = await import(
- "@/lib/video-processing-recovery"
- );
+ it.each([
+ { metadata: undefined, importPriority: undefined },
+ {
+ metadata: {
+ loomImportRun: {
+ runId: "bulk-run",
+ dispatch: "accepted" as const,
+ importPriority: "bulk" as const,
+ },
+ },
+ importPriority: "bulk",
+ },
+ ])(
+ "restarts a Loom import that exhausted its capacity retries in its original lane: $importPriority",
+ async ({ metadata, importPriority }) => {
+ mockDb
+ .mockReturnValueOnce(makeSelectChain([]))
+ .mockReturnValueOnce(makeSelectChain([]))
+ .mockReturnValueOnce(
+ makeSelectChain([
+ {
+ ...candidate,
+ orgId: "organization-1",
+ ...(metadata ? { metadata } : {}),
+ },
+ ]),
+ )
+ .mockReturnValueOnce(makeSelectChain([{ loomVideoId: "loom-video-1" }]))
+ .mockReturnValueOnce(makeSelectChain([]))
+ .mockReturnValueOnce(makeUpdateChain(1));
+ const { recoverFailedVideoProcessing } = await import(
+ "@/lib/video-processing-recovery"
+ );
- const result = await recoverFailedVideoProcessing();
+ const result = await recoverFailedVideoProcessing();
- expect(mockStartLoomImportWorkflow).toHaveBeenCalledWith(
- expect.objectContaining({
- videoId: "video-1",
- loomVideoId: "loom-video-1",
- rawFileKey: "user-1/video-1/raw.mp4",
- reuseExistingRawUpload: true,
- }),
- );
- expect(result.statuses).toEqual({ started: 1 });
- });
+ expect(mockStartLoomImportWorkflow).toHaveBeenCalledWith(
+ expect.objectContaining({
+ videoId: "video-1",
+ loomVideoId: "loom-video-1",
+ rawFileKey: "user-1/video-1/raw.mp4",
+ reuseExistingRawUpload: true,
+ importPriority,
+ }),
+ );
+ expect(result.statuses).toEqual({ started: 1 });
+ },
+ );
it("keeps a failed Loom workflow start eligible for Loom-specific recovery", async () => {
const restore = makeUpdateChain(1);
diff --git a/apps/web/app/api/internal/loom-imports/csv/route.ts b/apps/web/app/api/internal/loom-imports/csv/route.ts
index 92c2b068d..8194bda70 100644
--- a/apps/web/app/api/internal/loom-imports/csv/route.ts
+++ b/apps/web/app/api/internal/loom-imports/csv/route.ts
@@ -115,6 +115,7 @@ const ApiLive = HttpApiBuilder.api(Api).pipe(
orgId: organizationId,
actorId: organization.ownerId,
allowFolders: true,
+ importPriority: "bulk",
}),
);
return {
diff --git a/apps/web/lib/loom-csv-import.ts b/apps/web/lib/loom-csv-import.ts
index 3ebc09202..55bca0fcc 100644
--- a/apps/web/lib/loom-csv-import.ts
+++ b/apps/web/lib/loom-csv-import.ts
@@ -239,6 +239,7 @@ export async function importLoomVideoForOwner({
destination = {},
migrationRequestId,
migrationLeaseToken,
+ importPriority,
}: {
loomUrl: string;
orgId: Organisation.OrganisationId;
@@ -246,6 +247,7 @@ export async function importLoomVideoForOwner({
destination?: LoomImportDestination;
migrationRequestId?: string;
migrationLeaseToken?: string;
+ importPriority?: "customer" | "bulk";
}): Promise<LoomImportResult> {
const loomVideoId = extractLoomVideoId(loomUrl.trim());
if (!loomVideoId) {
@@ -372,6 +374,7 @@ export async function importLoomVideoForOwner({
bucketId: existingVideo.bucketId,
loomVideoId,
reuseExistingRawUpload: true,
+ importPriority,
});
} catch (error) {
if (error instanceof LoomImportStartError && error.canRetry) {
@@ -543,6 +546,7 @@ export async function importLoomVideoForOwner({
bucketId: Option.getOrNull(writable.bucketId),
loomVideoId,
loomDownloadUrl: downloadUrl,
+ importPriority,
});
} catch (error) {
if (error instanceof LoomImportStartError && error.canRetry) {
@@ -780,6 +784,7 @@ export async function processLoomCsvRows({
migrationRequestId,
migrationLeaseToken,
allowFolders = false,
+ importPriority,
}: {
rows: LoomCsvImportRow[];
orgId: Organisation.OrganisationId;
@@ -787,6 +792,7 @@ export async function processLoomCsvRows({
migrationRequestId?: string;
migrationLeaseToken?: string;
allowFolders?: boolean;
+ importPriority?: "customer" | "bulk";
}): Promise<LoomCsvImportResult> {
const inputRows = Array.isArray(rows) ? rows : [];
const normalizedRows = inputRows
@@ -918,6 +924,7 @@ export async function processLoomCsvRows({
destination: folderId ? { folderId } : {},
migrationRequestId,
migrationLeaseToken,
+ importPriority,
});
let spaceName = row.spaceName || undefined;
diff --git a/apps/web/lib/loom-import-redrive.ts b/apps/web/lib/loom-import-redrive.ts
index 1653c2029..fa220c591 100644
--- a/apps/web/lib/loom-import-redrive.ts
+++ b/apps/web/lib/loom-import-redrive.ts
@@ -101,6 +101,7 @@ export async function redriveLoomImport(
bucketId: row.bucketId,
loomVideoId: row.loomVideoId,
reuseExistingRawUpload: true,
+ importPriority: "bulk",
});
} catch (error) {
const message =
diff --git a/apps/web/lib/loom-import-start.ts b/apps/web/lib/loom-import-start.ts
index 8ba13a934..7fe788547 100644
--- a/apps/web/lib/loom-import-start.ts
+++ b/apps/web/lib/loom-import-start.ts
@@ -158,7 +158,13 @@ export async function startLoomImportWorkflow(payload: ImportPayload) {
queue: async (name, message, options) => {
if (!("runId" in message))
throw new Error("Missing Loom import run ID");
- receipt = { runId: message.runId, dispatch: "pending" };
+ receipt = {
+ runId: message.runId,
+ dispatch: "pending",
+ ...(payload.importPriority === "bulk"
+ ? { importPriority: "bulk" as const }
+ : {}),
+ };
await saveReceipt(payload, receipt);
attempted = true;
try {
diff --git a/apps/web/lib/video-pipeline-recovery.ts b/apps/web/lib/video-pipeline-recovery.ts
index 4deef1a19..e828cd801 100644
--- a/apps/web/lib/video-pipeline-recovery.ts
+++ b/apps/web/lib/video-pipeline-recovery.ts
@@ -204,6 +204,7 @@ async function recoverMediaCandidate(
bucketId: candidate.bucketId,
loomVideoId: candidate.loomVideoId,
reuseExistingRawUpload: true,
+ importPriority: receipt?.importPriority,
});
} else {
await start(processVideoWorkflow, [
diff --git a/apps/web/lib/video-processing-recovery.ts b/apps/web/lib/video-processing-recovery.ts
index 4bdd3d8a7..14979f276 100644
--- a/apps/web/lib/video-processing-recovery.ts
+++ b/apps/web/lib/video-processing-recovery.ts
@@ -249,6 +249,7 @@ async function recoverLoomCandidate({
loomVideoId,
reuseExistingRawUpload:
phase !== "uploading" && existingRawFileKey !== null,
+ importPriority: receipt?.importPriority,
});
return "started";
} catch (error) {
diff --git a/apps/web/workflows/import-loom-video.ts b/apps/web/workflows/import-loom-video.ts
index f0323cb7d..bdd99abd9 100644
--- a/apps/web/workflows/import-loom-video.ts
+++ b/apps/web/workflows/import-loom-video.ts
@@ -50,6 +50,7 @@ interface ImportLoomPayload {
agentOperationId?: string;
reuseExistingRawUpload?: boolean;
cleanupRawUpload?: boolean;
+ importPriority?: "customer" | "bulk";
}
const MINIMUM_VIDEO_SIZE = 1024;
@@ -427,6 +428,7 @@ async function startMediaServerProcessJob(
webhookSecret?: string;
inputExtension?: string;
priority: "bulk";
+ importPriority?: "customer" | "bulk";
},
recordDispatch: (
state: "accepted" | "rejected" | "uncertain",
@@ -709,6 +711,10 @@ async function processVideoOnMediaServer(
webhookSecret: webhookSecret || undefined,
inputExtension: getInputExtension(rawVideoUrl),
priority: "bulk",
+ importPriority:
+ worker === "importer"
+ ? (payload.importPriority ?? "customer")
+ : undefined,
},
(state, jobId) =>
recordLoomMediaDispatch({
diff --git a/packages/database/types/metadata.ts b/packages/database/types/metadata.ts
index 38351e422..734d7754f 100644
--- a/packages/database/types/metadata.ts
+++ b/packages/database/types/metadata.ts
@@ -9,6 +9,7 @@ export interface VideoMetadata {
loomImportRun?: {
runId: string;
dispatch: "pending" | "accepted" | "rejected" | "uncertain";
+ importPriority?: "customer" | "bulk";
mediaDispatch?: {
attemptId: string;
videoId?: string;