Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
- Fix claim_task to enforce max 5 tasks per worker (was unlimited) - Add session_task_count check before ANY claiming path - Add triggers to auto-decrement count on task complete/release - Update MAX_CONCURRENT_TASKS default from 3 to 5 - Update frontend fallback to show 5 task slots - Add Wasabi S3 storage for payload archival - Add inventory snapshots service (delta-only tracking) - Add sales analytics views and routes - Add high-frequency manager UI components - Reset hardcoded AZ 5-minute intervals (use UI to configure) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
54 lines
2.0 KiB
SQL
54 lines
2.0 KiB
SQL
-- Migration 126: Set AZ stores to 5-minute high-frequency crawls
|
|
-- Other states default to 60-minute (1 hour) intervals
|
|
|
|
-- ============================================================
|
|
-- SET AZ STORES TO 5-MINUTE INTERVALS (with 3-min jitter)
|
|
-- ============================================================
|
|
-- Base interval: 5 minutes
|
|
-- Jitter: +/- 3 minutes (so 2-8 minute effective range)
|
|
UPDATE dispensaries
|
|
SET
|
|
crawl_interval_minutes = 5,
|
|
next_crawl_at = NOW() + (RANDOM() * INTERVAL '5 minutes') -- Stagger initial crawls
|
|
WHERE state = 'AZ'
|
|
AND crawl_enabled = TRUE;
|
|
|
|
-- ============================================================
|
|
-- SET OTHER STATES TO 60-MINUTE INTERVALS (with 3-min jitter)
|
|
-- ============================================================
|
|
UPDATE dispensaries
|
|
SET
|
|
crawl_interval_minutes = 60,
|
|
next_crawl_at = NOW() + (RANDOM() * INTERVAL '60 minutes') -- Stagger initial crawls
|
|
WHERE state != 'AZ'
|
|
AND crawl_enabled = TRUE
|
|
AND crawl_interval_minutes IS NULL;
|
|
|
|
-- ============================================================
|
|
-- VERIFY RESULTS
|
|
-- ============================================================
|
|
-- SELECT state, crawl_interval_minutes, COUNT(*)
|
|
-- FROM dispensaries
|
|
-- WHERE crawl_enabled = TRUE
|
|
-- GROUP BY state, crawl_interval_minutes
|
|
-- ORDER BY state;
|
|
|
|
-- ============================================================
|
|
-- CREATE VIEW FOR MONITORING CRAWL LOAD
|
|
-- ============================================================
|
|
CREATE OR REPLACE VIEW v_crawl_load AS
|
|
SELECT
|
|
state,
|
|
crawl_interval_minutes,
|
|
COUNT(*) as store_count,
|
|
-- Crawls per hour = stores * (60 / interval)
|
|
ROUND(COUNT(*) * (60.0 / COALESCE(crawl_interval_minutes, 60))) as crawls_per_hour,
|
|
-- Assuming 30 sec per crawl, workers needed = crawls_per_hour / 120
|
|
ROUND(COUNT(*) * (60.0 / COALESCE(crawl_interval_minutes, 60)) / 120, 1) as workers_needed
|
|
FROM dispensaries
|
|
WHERE crawl_enabled = TRUE
|
|
GROUP BY state, crawl_interval_minutes
|
|
ORDER BY crawls_per_hour DESC;
|
|
|
|
COMMENT ON VIEW v_crawl_load IS 'Monitor crawl load by state and interval';
|