Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

refactor(web): migrate core workflows to workflow runtime

Richie McIlroyaba7f2ad0837
diff --git a/apps/web/workflows/admin-reprocess-video.ts b/apps/web/workflows/admin-reprocess-video.ts
index 36e34f89c..f6dd80104 100644
--- a/apps/web/workflows/admin-reprocess-video.ts
+++ b/apps/web/workflows/admin-reprocess-video.ts
@@ -5,13 +5,14 @@ import {
import { db } from "@cap/database";
import { videos, videoUploads } from "@cap/database/schema";
import { serverEnv } from "@cap/env";
-import { AwsCredentials, Storage } from "@cap/web-backend";
+import { AwsCredentials } from "@cap/web-backend/src/Aws";
+import { Storage } from "@cap/web-backend/src/Storage/index";
import { Video } from "@cap/web-domain";
import { eq } from "drizzle-orm";
import { Effect } from "effect";
import { FatalError } from "workflow";
-import { runPromise } from "@/lib/server";
import { decodeStorageVideo } from "@/lib/video-storage";
+import { runWorkflowPromise } from "@/lib/workflow-runtime";
interface AdminReprocessVideoWorkflowPayload {
videoId: string;
@@ -268,7 +269,7 @@ async function processExistingResultOnMediaServer(
const videoDomain = decodeStorageVideo(video);
const [bucket] =
- await Storage.getAccessForVideo(videoDomain).pipe(runPromise);
+ await Storage.getAccessForVideo(videoDomain).pipe(runWorkflowPromise);
const resultKey = `${video.ownerId}/${video.id}/result.mp4`;
const thumbnailKey = `${video.ownerId}/${video.id}/screenshot/screen-capture.jpg`;
@@ -278,7 +279,7 @@ async function processExistingResultOnMediaServer(
.getInternalSignedObjectUrl(resultKey, {
expiresIn: MEDIA_SERVER_PRESIGNED_GET_EXPIRES_SECONDS,
})
- .pipe(runPromise);
+ .pipe(runWorkflowPromise);
const outputPresignedUrl = await bucket
.getInternalPresignedPutUrl(
@@ -288,7 +289,7 @@ async function processExistingResultOnMediaServer(
},
{ expiresIn: MEDIA_SERVER_PRESIGNED_PUT_EXPIRES_SECONDS },
)
- .pipe(runPromise);
+ .pipe(runWorkflowPromise);
const thumbnailPresignedUrl = await bucket
.getInternalPresignedPutUrl(
@@ -298,7 +299,7 @@ async function processExistingResultOnMediaServer(
},
{ expiresIn: MEDIA_SERVER_PRESIGNED_PUT_EXPIRES_SECONDS },
)
- .pipe(runPromise);
+ .pipe(runWorkflowPromise);
const previewGifPresignedUrl = await bucket
.getInternalPresignedPutUrl(
@@ -309,7 +310,7 @@ async function processExistingResultOnMediaServer(
},
{ expiresIn: MEDIA_SERVER_PRESIGNED_PUT_EXPIRES_SECONDS },
)
- .pipe(runPromise);
+ .pipe(runWorkflowPromise);
const webhookUrl = `${webhookBaseUrl}/api/webhooks/media-server/progress`;
const webhookSecret = serverEnv().MEDIA_SERVER_WEBHOOK_SECRET;
@@ -408,7 +409,7 @@ async function invalidateResultCache(
try {
const cloudfront = new CloudFrontClient({
region: serverEnv().CAP_AWS_REGION || "us-east-1",
- credentials: await runPromise(
+ credentials: await runWorkflowPromise(
Effect.map(AwsCredentials, (c) => c.credentials),
),
});
diff --git a/apps/web/workflows/edit-video.ts b/apps/web/workflows/edit-video.ts
index 7d4f1f6b2..019d2f970 100644
--- a/apps/web/workflows/edit-video.ts
+++ b/apps/web/workflows/edit-video.ts
@@ -16,18 +16,19 @@ import type {
VideoMetadata,
} from "@cap/database/types";
import { serverEnv } from "@cap/env";
-import { AwsCredentials, Storage } from "@cap/web-backend";
+import { AwsCredentials } from "@cap/web-backend/src/Aws";
+import { Storage } from "@cap/web-backend/src/Storage/index";
import { Video } from "@cap/web-domain";
import { and, eq } from "drizzle-orm";
import { Effect } from "effect";
import { FatalError } from "workflow";
-import { runPromise } from "@/lib/server";
import { transcribeVideo } from "@/lib/transcribe";
import {
getEditSpecOutputDuration,
remapCurrentOutputTimeThroughEdit,
} from "@/lib/video-edits";
import { decodeStorageVideo } from "@/lib/video-storage";
+import { runWorkflowPromise } from "@/lib/workflow-runtime";
interface EditVideoWorkflowPayload {
videoId: string;
@@ -259,13 +260,13 @@ async function renderVideoEditOnMediaServer(
const [bucket] = await Storage.getAccessForVideo(
decodeStorageVideo(video),
- ).pipe(runPromise);
+ ).pipe(runWorkflowPromise);
const sourceUrl = await bucket
.getInternalSignedObjectUrl(sourceKey, {
expiresIn: MEDIA_SERVER_PRESIGNED_GET_EXPIRES_SECONDS,
})
- .pipe(runPromise);
+ .pipe(runWorkflowPromise);
const outputKey = `${userId}/${videoId}/result.mp4`;
const thumbnailKey = `${userId}/${videoId}/screenshot/screen-capture.jpg`;
@@ -279,13 +280,13 @@ async function renderVideoEditOnMediaServer(
},
{ expiresIn: MEDIA_SERVER_PRESIGNED_PUT_EXPIRES_SECONDS },
)
- .pipe(runPromise);
+ .pipe(runWorkflowPromise);
const outputVerificationUrl = await bucket
.getInternalSignedObjectUrl(outputKey, {
expiresIn: MEDIA_SERVER_PRESIGNED_GET_EXPIRES_SECONDS,
})
- .pipe(runPromise);
+ .pipe(runWorkflowPromise);
const thumbnailPresignedUrl = await bucket
.getInternalPresignedPutUrl(
@@ -295,7 +296,7 @@ async function renderVideoEditOnMediaServer(
},
{ expiresIn: MEDIA_SERVER_PRESIGNED_PUT_EXPIRES_SECONDS },
)
- .pipe(runPromise);
+ .pipe(runWorkflowPromise);
const previewGifPresignedUrl = await bucket
.getInternalPresignedPutUrl(
@@ -306,7 +307,7 @@ async function renderVideoEditOnMediaServer(
},
{ expiresIn: MEDIA_SERVER_PRESIGNED_PUT_EXPIRES_SECONDS },
)
- .pipe(runPromise);
+ .pipe(runWorkflowPromise);
const webhookUrl = `${webhookBaseUrl}/api/webhooks/media-server/progress?retryable=true`;
const webhookSecret = serverEnv().MEDIA_SERVER_WEBHOOK_SECRET;
@@ -444,13 +445,13 @@ async function verifyRenderedEditOutput(
const [bucket] = await Storage.getAccessForVideo(
decodeStorageVideo(video),
- ).pipe(runPromise);
+ ).pipe(runWorkflowPromise);
const outputKey = `${userId}/${videoId}/result.mp4`;
const outputUrl = await bucket
.getInternalSignedObjectUrl(outputKey, {
expiresIn: MEDIA_SERVER_PRESIGNED_GET_EXPIRES_SECONDS,
})
- .pipe(runPromise);
+ .pipe(runWorkflowPromise);
let lastError: Error | undefined;
@@ -522,15 +523,15 @@ async function queueTranscriptionRegeneration(
async function clearTranscriptObjects(video: typeof videos.$inferSelect) {
const [bucket] = await Storage.getAccessForVideo(
decodeStorageVideo(video),
- ).pipe(runPromise);
+ ).pipe(runWorkflowPromise);
const prefix = `${video.ownerId}/${video.id}/transcription`;
- const listed = await bucket.listObjects({ prefix }).pipe(runPromise);
+ const listed = await bucket.listObjects({ prefix }).pipe(runWorkflowPromise);
const objects = (listed.Contents ?? [])
.map((object) => ({ Key: object.Key }))
.filter((object): object is { Key: string } => Boolean(object.Key));
if (objects.length > 0) {
- await bucket.deleteObjects(objects).pipe(runPromise);
+ await bucket.deleteObjects(objects).pipe(runWorkflowPromise);
}
}
@@ -631,7 +632,7 @@ async function invalidateEditedVideoCache(
try {
const cloudfront = new CloudFrontClient({
region: serverEnv().CAP_AWS_REGION || "us-east-1",
- credentials: await runPromise(
+ credentials: await runWorkflowPromise(
Effect.map(AwsCredentials, (credentials) => credentials.credentials),
),
});
diff --git a/apps/web/workflows/import-loom-video.ts b/apps/web/workflows/import-loom-video.ts
index 0757d1a00..f68417e8a 100644
--- a/apps/web/workflows/import-loom-video.ts
+++ b/apps/web/workflows/import-loom-video.ts
@@ -2,12 +2,12 @@ import { randomUUID } from "node:crypto";
import { db } from "@cap/database";
import { agentApiOperations, videos, videoUploads } from "@cap/database/schema";
import { serverEnv } from "@cap/env";
-import { Storage } from "@cap/web-backend";
+import { Storage } from "@cap/web-backend/src/Storage/index";
import { Video } from "@cap/web-domain";
import { eq } from "drizzle-orm";
import { Effect } from "effect";
import { FatalError } from "workflow";
-import { runPromise } from "@/lib/server";
+import { runWorkflowPromise } from "@/lib/workflow-runtime";
interface ImportLoomPayload {
videoId: string;
@@ -319,7 +319,7 @@ async function downloadLoomToS3(
},
{ expiresIn: MEDIA_SERVER_PRESIGNED_PUT_EXPIRES_SECONDS },
);
- }).pipe(runPromise);
+ }).pipe(runWorkflowPromise);
const videoBuffer = await downloadVideoContent(freshDownloadUrl);
@@ -512,7 +512,7 @@ async function processVideoOnMediaServer(
thumbnailPresignedUrl,
previewGifPresignedUrl,
};
- }).pipe(runPromise);
+ }).pipe(runWorkflowPromise);
const webhookUrl = `${webhookBaseUrl}/api/webhooks/media-server/progress?retryable=true`;
const webhookSecret = serverEnv().MEDIA_SERVER_WEBHOOK_SECRET;