The Price Monitoring Cron API is a scheduled Edge Function that automatically monitors product prices from competitor sources. It runs on a schedule (hourly) and orchestrates price checking through the Python backend.
Edge Function: price-monitoring-cron
Trigger: Scheduled (hourly) or manual invocation
Backend Service: Python API at /api/v1/price-monitoring/check-now
Supabase Cron (hourly)
↓
Edge Function (price-monitoring-cron)
↓
Python Backend API (/api/v1/price-monitoring/check-now)
↓
CompetitorScraperService
├─→ Firecrawl API (scrape competitor pages)
├─→ CreditsIntegrationService (debit credits)
├─→ AICallLogger (log usage)
├─→ Database (save price history)
└─→ PriceAlertService (check alerts)
This is a cron job that requires a secret header for security:
X-Cron-Secret: <cron_secret>
The secret must match the CRON_SECRET environment variable.
While this function is designed to run on a schedule, it can be manually triggered:
Method: POST
Path: /
Headers:
X-Cron-Secret: <cron_secret>
Response:
{
success: true,
message: string,
processed: number, // Total products processed
succeeded: number, // Successfully monitored
failed: number, // Failed to monitor
results: Array<{
product_id: string,
product_name: string,
status: 'success' | 'failed',
price_changes: number,
alerts_triggered: number,
error?: string
}>
}
The function calls the database function get_products_due_for_monitoring() which returns products where:
next_check_at <= NOW()is_active = trueFor each product, the function:
POST /api/v1/price-monitoring/check-nowAfter processing, the next_check_at is updated based on the monitoring frequency:
hourly → +1 hourdaily → +1 dayweekly → +7 daysmonthly → +30 days| Frequency | Check Interval | Use Case |
|---|---|---|
hourly |
Every hour | High-priority products |
daily |
Every 24 hours | Standard monitoring |
weekly |
Every 7 days | Low-priority products |
monthly |
Every 30 days | Occasional checks |
When price changes are detected, the system checks for active alerts:
Alert Types:
price_drop - Price decreased by X%price_increase - Price increased by X%threshold_below - Price fell below thresholdthreshold_above - Price rose above thresholdAlert Actions:
Tracks each monitoring execution:
{
id: string,
product_id: string,
status: 'pending' | 'processing' | 'completed' | 'failed',
sources_checked: number,
prices_found: number,
credits_used: number,
started_at: string,
completed_at: string,
error_message?: string
}
Stores historical price data:
{
id: string,
product_id: string,
source_id: string,
price: number,
currency: string,
availability: boolean,
scraped_at: string,
metadata: object
}
User-configured price alerts:
{
id: string,
user_id: string,
product_id: string,
alert_type: string,
threshold_value: number,
is_active: boolean,
last_triggered_at?: string
}
{
success: false,
error: string,
processed: number,
succeeded: number,
failed: number
}
Common Errors:
401 - Invalid cron secret500 - Database query failed503 - Python backend unavailableThe function logs detailed information: