Skip to content

Component Details

This document outlines the detailed implementation logic for the core Lambda functions in the Dashcam Video Integration Service.

1. Request Handler (VideoRequestFunction)

File: src/request_handler.py Trigger: SQS (video-request-queue.fifo)

Role: Concepts the request from the Fleet Tracking (via SNS/SQS), validates/dedplicates it, and forwards the command to Flespi to initiate the asynchronous video retrieval process.

Workflow:

  1. Input Processing:
    • Receives deviceId, startTime, duration, customerId, and eventId from SQS message payload.
    • Adjustment: Subtracts 5 seconds from startTime to ensure event context is captured.
  2. Deduplication (Hash Check):
    • Generates a deterministic SHA-256 hash based on deviceId, adjusted_startTime, duration, and eventId.
    • Checks the DashCamVideoRequestTable for this hash.
    • Duplicate: If status is VIDEO_REQUESTED, logs and ignores the request to prevent redundant processing.
    • Retry: If status is FAILED (and retry_count < 3):
      • Increments the retry_count.
      • Generates a NEW correlation_id.
      • Proceeds to call Flespi.
    • New: If no record exists, creates a new entry.
  3. Flespi Command:
    • Sends a POST request to Flespi’s command-queue API.
    • Meta Injection: Embeds the correlation_id, asset_id, and event_id into the command’s meta object.
  4. State Persistence:
    • Saves/Updates the record in DashCamVideoRequestTable with status: VIDEO_REQUESTED.
    • Sets a TTL of 6 months for automatic cleanup.

2. Process Handler (VideoProcessFunction)

File: src/process_handler.py Trigger: SQS (video-notify-queue) -> Derived from Flespi Success Webhook

Role: Processes the “Success” webhook from Flespi, manages the upload to Uploadcare, and updates Skyledge.

Workflow:

  1. Validation:
    • Extracts command_meta.correlation_id from the webhook payload.
    • If missing, ignores the request.
  2. Resume Check:
    • Checks DashCamVideoProcessTable for an existing state record (correlation_id).
    • If found and contains an upload_token, resumes polling immediately, skipping the initial upload call.
  3. Data Retrieval:
    • If no processing state exists, fetches immutable request details (Asset ID, Customer) from * DashCamVideoRequestTable* using the correlation_id GSI.
  4. Upload Initiation:
    • Calls Uploadcare from_url API.
    • Immediately saves the returned upload_token to DashCamVideoProcessTable with status PROCESSING and a 6-month TTL.
  5. Polling:
    • Polls the Uploadcare status endpoint until the file is ready.
  6. Completion:
    • Calls the Skyledge API to attach the uploaded file to the target Asset/Event.
    • Updates DashCamVideoProcessTable status to COMPLETED.

3. Retry Handler (VideoRetryFunction)

File: src/retry_handler.py Trigger: SQS (video-failure-queue) -> Derived from Flespi Failure/Timeout Webhook

Role: Manages failures from Flespi. It marks the request as failed and triggers a retry if applicable.

Workflow:

  1. Identification:
    • Extracts correlation_id from the failure webhook.
    • Locates the corresponding request in DashCamVideoRequestTable.
  2. Failure Marking:
    • Updates the status in DashCamVideoRequestTable to FAILED.
    • Note: Does NOT increment the retry count here (that happens in Request Handler upon retry execution).
  3. Retry Decision:
    • Checks the current retry_count from the record.
    • Retry: If retry_count < 3:
      • Re-queues the original request payload (with original start time restored) to the VideoRequestQueue.
    • Stop: If retry_count >= 3, leaves the status as FAILED (DLQ handles the final message).