MCPcopy Index your code
hub / github.com/CapSoftware/Cap / startMediaServerProcessJob

Function startMediaServerProcessJob

apps/web/workflows/process-video.ts:142–222  ·  view source on GitHub ↗
(
	mediaServerUrl: string,
	body: {
		videoId: string;
		userId: string;
		videoUrl: string;
		outputPresignedUrl: string;
		thumbnailPresignedUrl: string;
		previewGifPresignedUrl: string;
		webhookUrl: string;
		webhookSecret?: string;
		inputExtension: string;
	},
)

Source from the content-addressed store, hash-verified

140}
141
142async function startMediaServerProcessJob(
143 mediaServerUrl: string,
144 body: {
145 videoId: string;
146 userId: string;
147 videoUrl: string;
148 outputPresignedUrl: string;
149 thumbnailPresignedUrl: string;
150 previewGifPresignedUrl: string;
151 webhookUrl: string;
152 webhookSecret?: string;
153 inputExtension: string;
154 },
155): Promise<string> {
156 for (let attempt = 0; attempt < MEDIA_SERVER_START_MAX_ATTEMPTS; attempt++) {
157 const headers: Record<string, string> = {
158 "Content-Type": "application/json",
159 };
160 if (body.webhookSecret) {
161 headers["x-media-server-secret"] = body.webhookSecret;
162 }
163
164 const response = await fetch(`${mediaServerUrl}/video/process`, {
165 method: "POST",
166 headers,
167 body: JSON.stringify(body),
168 });
169
170 if (response.ok) {
171 const { jobId } = (await response.json()) as { jobId: string };
172 return jobId;
173 }
174
175 const errorData = (await response.json().catch(() => ({}))) as {
176 error?: string;
177 code?: string;
178 details?: string;
179 instanceId?: string;
180 pid?: number;
181 activeVideoProcesses?: number;
182 maxConcurrentVideoProcesses?: number;
183 jobCount?: number;
184 };
185 const baseErrorMessage =
186 errorData.error ||
187 errorData.details ||
188 "Video processing failed to start";
189 const busyDiagnostics =
190 errorData.code === "SERVER_BUSY"
191 ? [
192 errorData.instanceId ? `instance=${errorData.instanceId}` : null,
193 typeof errorData.pid === "number" ? `pid=${errorData.pid}` : null,
194 typeof errorData.activeVideoProcesses === "number" &&
195 typeof errorData.maxConcurrentVideoProcesses === "number"
196 ? `active=${errorData.activeVideoProcesses}/${errorData.maxConcurrentVideoProcesses}`
197 : null,
198 typeof errorData.jobCount === "number"
199 ? `jobCount=${errorData.jobCount}`

Callers 1

Calls 2

waitForRetryFunction · 0.70
fetchFunction · 0.50

Tested by

no test coverage detected