kingtommy dot com

MeetCritique MC Reel

Client project · Excerpts from the live MeetCritique code

A customer can export a reviewed video as one MP4 with the judge's tooltips, the score and the branding burned in, and a two second pause at each tooltip.

Clicking Export Video inserts a pending row and returns at once. WordPress then renders the overlay images and a manifest and uploads them to S3. The encoding itself runs on AWS Lambda with ffmpeg, because the host has no ffmpeg and MediaConvert cannot hold a frame.

The click starts the Lambda with an asynchronous invoke, so rendering begins within seconds. The worker claims the job, renders, uploads the MP4 to a presigned URL and reports back. It holds no AWS credentials: WordPress hands it presigned URLs. A WP cron job and a once-a-minute EventBridge poll are the safety nets if the invoke fails.

A double click or an overlapping cron run must not render the same reel twice. A row moves from pending to processing with a single conditional UPDATE, and only the run that changes the row proceeds. Rows stuck in processing return to pending after ten minutes.

Queue the job ajax/submit.php:3677-3683
$inserted = $wpdb->insert('app_video_mc_reels', [
    'video_id'    => $video_id,
    'status'      => 'pending',
    'created_by'  => get_current_user_id(),
    'datecreated' => $now,
    'dateupdated' => $now,
]);
Start the worker lib/McReel.php:1226-1230
self::lambda_client()->invoke([
    'FunctionName'   => $fn,
    'InvocationType' => 'Event',
    'Payload'        => '{}',
]);
Claim the job atomically lib/McReel.php:741-745
$claimed = $wpdb->query($wpdb->prepare(
    "UPDATE app_video_mc_reels SET status='processing', dateupdated=%s WHERE id=%d AND status='pending'",
    current_time('mysql'), $reel_id
));
if ($claimed !== 1) return;   // lost the race; another run owns this reel

All demos