Skip to main content

Overview

The Queue API provides endpoints for managing BullMQ media processing jobs and monitoring queue health. Jobs are enqueued via this API and processed by background workers. Base Path: /api/queue Key Features:
  • Enqueue media jobs (transcoding, thumbnails, captions)
  • Real-time queue statistics (depth, waiting, active, completed)
  • Subscription tier enforcement
  • Taxonomy cache management

GET /api/queue/stats

Returns BullMQ queue depths and taxonomy cache statistics. Useful for dashboard observability. Authentication: None (public endpoint)
boolean
Request success status
object
BullMQ queue statistics object containing:
  • waiting - Jobs waiting to be processed
  • active - Currently processing jobs
  • completed - Successfully completed jobs
  • failed - Failed jobs
  • delayed - Jobs scheduled for future execution
object
Taxonomy cache statistics:
  • size - Number of cached entries
  • hits - Cache hit count
  • misses - Cache miss count
Example Request:
Response:
Use Cases:
  • Health check dashboards
  • Queue depth monitoring alerts
  • Performance analytics
  • Worker scaling decisions

POST /api/queue/media

Enqueue a media job that already exists in the Directus media_jobs collection. Authentication: Directus JWT (Bearer token)
You must create the Directus media_jobs record before calling this endpoint. This endpoint only pushes the job into BullMQ so workers can pick it up.

Request Parameters

string
required
UUID of the existing media_jobs Directus record
string
required
Operation type (e.g., transcoding, thumbnail, caption_generation). Used for tier validation.
string
UUID of the input file from Directus directus_files (optional)
string
URL of remote input file (optional, alternative to input_file_id)
object
Job-specific parameters (e.g., {"format": "mp4", "resolution": "1080p"})
string
UUID of the associated platform_connections record (optional)
number
Job priority (1-100, default: 10). Lower numbers = higher priority.

Response

boolean
Request success status
string
BullMQ job ID (UUID) assigned by the queue
string
Directus media_jobs record UUID (echoed from request)

Example Request

Success Response:

Subscription Tier Enforcement

The endpoint validates if the user’s subscription tier allows the requested operation: From queue.js:88:
Tier Limit Error Response:
Tier Feature Unavailable:

Supported Operations

Common operation values (validated against subscription tier):
  • transcoding - Video format conversion
  • thumbnail - Generate video thumbnail
  • caption_generation - AI caption generation
  • download - Download remote media
  • upload - Upload processing
  • analysis - Media analysis/metadata extraction

POST /api/queue/taxonomy/invalidate

Bust the taxonomy cache (e.g., after admin updates taxonomy_terms in Directus). Authentication: None (internal loopback only)
This endpoint is designed for internal use only. It should be called via localhost after Directus webhooks update taxonomy data.
Example Request:
Response:
Use Case: Directus webhook configuration:

Queue Architecture

Job Lifecycle

  1. Create Directus Record - Client creates media_jobs record with status=pending
  2. Enqueue - Client calls POST /api/queue/media with jobId
  3. BullMQ Processing - Worker picks up job from queue
  4. Status Updates - Worker updates Directus record (status=processing, status=completed, status=failed)
  5. Client Polling - Client polls Directus media_jobs record for status changes

Queue Configuration

From server/utils/actionBus.js:

Job Priority Levels

  • 1-3 - Critical (real-time user actions)
  • 4-6 - High (scheduled urgent tasks)
  • 7-10 - Normal (default background processing)
  • 11+ - Low (batch operations, cleanup)

Error Handling

Missing required fields:
Invalid token:
Queue enqueue failure:
Stats retrieval failure:

Monitoring & Observability

Queue Metrics Dashboard

Use the /stats endpoint to build real-time dashboards:

Alerting Thresholds

Recommended alert triggers:
  • High queue depth: waiting > 100 (consider scaling workers)
  • High failure rate: failed / (completed + failed) > 0.1 (10%)
  • Stalled jobs: active > 0 for > 30 minutes (worker crash?)

Integration Example

Complete workflow for enqueuing a transcoding job:

Next Steps

Captions API

Generate AI-powered captions (one of the queue operations)

Credentials API

Manage encrypted credentials for media jobs