fix(tasks): Filter out disabled dispensaries in createStaggeredTasks

Tasks were being created for dispensaries with crawl_enabled=false
(duplicates, deprecated stores). Added EXISTS check to filter only
crawl_enabled=true stores before creating tasks.

This prevents errors like:
"Dispensary 207 not found or not crawl_enabled"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Kelly
2025-12-14 03:07:03 -07:00
parent e7b392141a
commit f48a503e82

View File

@@ -797,8 +797,9 @@ class TaskService {
} = options;
// Filter out dispensaries that:
// 1. Already have a pending/claimed/running task for this role
// 2. Had this role completed recently (within skipRecentHours)
// 1. Are not crawl_enabled (disabled or duplicate)
// 2. Already have a pending/claimed/running task for this role
// 3. Had this role completed recently (within skipRecentHours)
const result = await pool.query(`
WITH input_ids AS (
SELECT unnest($1::int[]) as dispensary_id
@@ -806,7 +807,12 @@ class TaskService {
eligible_ids AS (
SELECT i.dispensary_id
FROM input_ids i
WHERE NOT EXISTS (
-- Must be crawl_enabled
WHERE EXISTS (
SELECT 1 FROM dispensaries d
WHERE d.id = i.dispensary_id AND d.crawl_enabled = true
)
AND NOT EXISTS (
-- No pending/active task for same role
SELECT 1 FROM worker_tasks t
WHERE t.dispensary_id = i.dispensary_id