Open source CapCut alternative.
TypeScript
feat(site): drain a generic donkey-jobs queue from the Cut worker
David Lefaedf099d390
diff --git a/site/src/cut/worker/cf/worker.ts b/site/src/cut/worker/cf/worker.tsindex 2ff8a2e6..c3e98b19 100644--- a/site/src/cut/worker/cf/worker.ts+++ b/site/src/cut/worker/cf/worker.ts@@ -18,6 +18,8 @@ type WorkerEnv = MediaEnv & {CUT_WAKE_SECRET: string;CUT_COPY_EXECUTE_URL: string;CUT_COPY_EXECUTE_SECRET: string;+ JOBS_EXECUTE_URL: string;+ JOBS_EXECUTE_SECRET: string;CLOUDFLARE_KV_API_TOKEN: string;};@@ -28,7 +30,7 @@ type QueueMessage = {ack(): void;retry(opts?: { delaySeconds?: number }): void;};-type QueueBatch = { messages: QueueMessage[] };+type QueueBatch = { queue: string; messages: QueueMessage[] };// How many container replicas the render pool runs. Each one takes a single// job at a time, so this is also the number of renders that can be in flight@@ -103,12 +105,16 @@ export default {return new Response("donkey-cut-worker", { status: 200 });},- // Share-copy queue consumer (donkey-cut-copy, wrangler.jsonc): one message- // per batch, one batch at a time, so copies drain serially no matter how- // many viewers ask at once. The copy itself runs on the hosted API — this- // handler only paces it and carries the queue's retry semantics: 2xx acks,- // anything else redelivers after a delay.+ // Queue consumer for both queues in wrangler.jsonc — share copies+ // (donkey-cut-copy) and the site's generic async jobs (donkey-jobs). Each+ // drains serially: one message per batch, one batch at a time. The work+ // itself runs on the hosted API — this handler only paces it and carries the+ // queue's retry semantics: 2xx acks, anything else redelivers after a delay.async queue(batch: QueueBatch, env: WorkerEnv): Promise<void> {+ const target =+ batch.queue === "donkey-jobs"+ ? { url: env.JOBS_EXECUTE_URL, secret: env.JOBS_EXECUTE_SECRET }+ : { url: env.CUT_COPY_EXECUTE_URL, secret: env.CUT_COPY_EXECUTE_SECRET };for (const message of batch.messages) {const jobId = (message.body as { jobId?: unknown } | null)?.jobId;if (typeof jobId !== "string" || !jobId) {@@ -116,10 +122,10 @@ export default {continue;}try {- const res = await fetch(env.CUT_COPY_EXECUTE_URL, {+ const res = await fetch(target.url, {method: "POST",headers: {- Authorization: `Bearer ${env.CUT_COPY_EXECUTE_SECRET}`,+ Authorization: `Bearer ${target.secret}`,"Content-Type": "application/json",},body: JSON.stringify({ jobId }),diff --git a/site/src/cut/worker/wrangler.jsonc b/site/src/cut/worker/wrangler.jsoncindex f8322de0..49f24e55 100644--- a/site/src/cut/worker/wrangler.jsonc+++ b/site/src/cut/worker/wrangler.jsonc@@ -48,9 +48,13 @@{ "pattern": "worker.donkeycut.com", "custom_domain": true }],"migrations": [{ "tag": "v1", "new_sqlite_classes": ["CutRenderWorker"] }],- // Share-copy jobs drain serially: one message per batch, one batch in- // flight, so a burst of copy requests can't stampede R2 or the database.- // Create the queue once: npx wrangler queues create donkey-cut-copy+ // Share-copy jobs and the site's generic async jobs drain serially: one+ // message per batch, one batch in flight, so a burst can't stampede R2 or+ // the database. Create each queue once:+ // npx wrangler queues create donkey-cut-copy+ // npx wrangler queues create donkey-jobs+ // The jobs consumer needs JOBS_EXECUTE_URL and JOBS_EXECUTE_SECRET set with+ // `wrangler secret put`, mirroring the CUT_COPY_EXECUTE_* pair."queues": {"consumers": [{@@ -59,6 +63,13 @@"max_concurrency": 1,"max_retries": 10,"retry_delay": 30+ },+ {+ "queue": "donkey-jobs",+ "max_batch_size": 1,+ "max_concurrency": 1,+ "max_retries": 10,+ "retry_delay": 30}]}