Overview
Two collections manage background operations:media_jobs for BullMQ job records, and hitl_sessions for human-in-the-loop login requests.
media_jobs
Tracks BullMQ background jobs for media processing operations. Each job record corresponds to a queue entry in Redis.Purpose
- Track status of background media operations
- Store job metadata, progress, and results
- Enable job retry and error handling
- Link jobs to creator profiles and media items
- Provide audit trail for all media operations
Job Types
| Type | Description | Worker Queue |
|---|---|---|
scrape_profile | Scrape platform for new content and metrics | scrape-jobs |
publish_post | Publish scheduled post to platform(s) | media-jobs |
apply_watermark | Add watermark to image/video using ImageMagick | media-jobs |
create_teaser | Generate video preview using FFmpeg | media-jobs |
crop_media | Crop/resize media file | media-jobs |
compress_media | Compress media for faster delivery | media-jobs |
Key Fields
| Field | Type | Description |
|---|---|---|
id | UUID | Primary key |
job_type | String | One of the job types listed above |
status | String | queued, processing, completed, failed |
creator_profile_id | Foreign Key | Optional link to creator_profiles |
media_id | Foreign Key | Optional link to scraped_media |
scheduled_post_id | Foreign Key | Optional link to scheduled_posts |
bull_job_id | String | BullMQ Redis job ID for status tracking |
params | JSON | Job-specific parameters |
progress | Integer | 0-100 completion percentage |
result | JSON | Job output data on completion |
error_message | Text | Error details if status=failed |
retry_count | Integer | Number of retry attempts |
started_at | DateTime | When job processing began |
completed_at | DateTime | When job finished (success or failure) |
created_at | DateTime | Job creation timestamp |
Example Queries
Create Scrape Job
Monitor Job Status
List Recent Jobs
Find Failed Jobs
hitl_sessions
Human-in-the-loop login requests displayed as yellow dashboard alerts when automated scraping requires manual intervention.Purpose
- Request manual login when platform cookies expire
- Display browser extension flow prompts in dashboard
- Track session resolution status
- Coordinate between automated scraping and human intervention
Key Fields
| Field | Type | Description |
|---|---|---|
id | UUID | Primary key |
creator_profile_id | Foreign Key | Links to creator_profiles |
platform | String | Platform requiring login |
session_type | String | login_required, cookies_expired, 2fa_required |
status | String | pending, in_progress, resolved, cancelled |
alert_message | Text | Message shown in dashboard alert |
resolution_method | String | How resolved: browser_extension, manual_cookies, oauth |
resolved_at | DateTime | When session was resolved |
expires_at | DateTime | Auto-cancel if not resolved by this time |
created_at | DateTime | Session creation timestamp |
Dashboard Integration
HITL sessions trigger yellow banner alerts in the dashboard:Example Queries
Create HITL Session
List Active Sessions
Resolve Session
Related Collections
creator_profiles- Platform accounts that jobs operate onscraped_media- Content processed by media jobsscheduled_posts- Posts published by publish_post jobsplatform_sessions- Browser cookies that resolve HITL sessions
Workflow Integration
Scraping with HITL Flow
- User clicks “Let’s Go” scrape button on dashboard
- System checks
platform_sessionsfor valid cookies - If cookies exist: Create
media_jobsentry with typescrape_profile - If no cookies: Create
hitl_sessionsentry instead - Dashboard shows yellow banner: “Login required. Click to connect.”
- User completes login via browser extension
- Extension captures cookies → stored in
platform_sessions - HITL session marked
resolved - System creates
media_jobsentry, scraping proceeds
Media Processing Flow
- User clicks crop/watermark/teaser button in Media Library
- Frontend creates
media_jobsentry viaPOST /api/queue/enqueue - BullMQ worker picks up job from Redis queue
- Worker updates job
statusandprogressfields - On completion: job
resultcontains output file URLs - Frontend polls job status and displays result
Best Practices
- Poll job status - Use
bull_job_idto track BullMQ queue position - Implement retry logic - Jobs with
retry_count < 3can be retried - Clean up completed jobs - Archive jobs older than 30 days
- Monitor HITL expiry - Auto-cancel sessions after 24 hours
- Handle concurrent HITLs - Only show one HITL alert per platform at a time
BullMQ Integration
The media worker (media-worker/index.js) processes jobs from Redis queues:
See Also
- Creator Profiles - Platform account management
- Media Collections - Content storage
- Stagehand MCP Tools - Browser automation for scraping
