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:
- Input Processing:
- Receives
deviceId,startTime,duration,customerId, andeventIdfrom SQS message payload. - Adjustment: Subtracts 5 seconds from
startTimeto ensure event context is captured.
- Receives
- Deduplication (Hash Check):
- Generates a deterministic SHA-256 hash based on
deviceId,adjusted_startTime,duration, andeventId. - 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(andretry_count< 3):- Increments the
retry_count. - Generates a NEW
correlation_id. - Proceeds to call Flespi.
- Increments the
- New: If no record exists, creates a new entry.
- Generates a deterministic SHA-256 hash based on
- Flespi Command:
- Sends a POST request to Flespi’s
command-queueAPI. - Meta Injection: Embeds the
correlation_id,asset_id, andevent_idinto the command’smetaobject.
- Sends a POST request to Flespi’s
- State Persistence:
- Saves/Updates the record in DashCamVideoRequestTable with
status: VIDEO_REQUESTED. - Sets a TTL of 6 months for automatic cleanup.
- Saves/Updates the record in DashCamVideoRequestTable with
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:
- Validation:
- Extracts
command_meta.correlation_idfrom the webhook payload. - If missing, ignores the request.
- Extracts
- 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.
- Checks DashCamVideoProcessTable for an existing state record (
- Data Retrieval:
- If no processing state exists, fetches immutable request details (Asset ID, Customer) from *
DashCamVideoRequestTable* using the
correlation_idGSI.
- If no processing state exists, fetches immutable request details (Asset ID, Customer) from *
DashCamVideoRequestTable* using the
- Upload Initiation:
- Calls Uploadcare
from_urlAPI. - Immediately saves the returned
upload_tokento DashCamVideoProcessTable with statusPROCESSINGand a 6-month TTL.
- Calls Uploadcare
- Polling:
- Polls the Uploadcare status endpoint until the file is
ready.
- Polls the Uploadcare status endpoint until the file is
- 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:
- Identification:
- Extracts
correlation_idfrom the failure webhook. - Locates the corresponding request in DashCamVideoRequestTable.
- Extracts
- 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).
- Updates the status in DashCamVideoRequestTable to
- Retry Decision:
- Checks the current
retry_countfrom the record. - Retry: If
retry_count < 3:- Re-queues the original request payload (with original start time restored) to the
VideoRequestQueue.
- Re-queues the original request payload (with original start time restored) to the
- Stop: If
retry_count >= 3, leaves the status asFAILED(DLQ handles the final message).
- Checks the current