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:
@@ -797,8 +797,9 @@ class TaskService {
|
|||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
// Filter out dispensaries that:
|
// Filter out dispensaries that:
|
||||||
// 1. Already have a pending/claimed/running task for this role
|
// 1. Are not crawl_enabled (disabled or duplicate)
|
||||||
// 2. Had this role completed recently (within skipRecentHours)
|
// 2. Already have a pending/claimed/running task for this role
|
||||||
|
// 3. Had this role completed recently (within skipRecentHours)
|
||||||
const result = await pool.query(`
|
const result = await pool.query(`
|
||||||
WITH input_ids AS (
|
WITH input_ids AS (
|
||||||
SELECT unnest($1::int[]) as dispensary_id
|
SELECT unnest($1::int[]) as dispensary_id
|
||||||
@@ -806,7 +807,12 @@ class TaskService {
|
|||||||
eligible_ids AS (
|
eligible_ids AS (
|
||||||
SELECT i.dispensary_id
|
SELECT i.dispensary_id
|
||||||
FROM input_ids i
|
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
|
-- No pending/active task for same role
|
||||||
SELECT 1 FROM worker_tasks t
|
SELECT 1 FROM worker_tasks t
|
||||||
WHERE t.dispensary_id = i.dispensary_id
|
WHERE t.dispensary_id = i.dispensary_id
|
||||||
|
|||||||
Reference in New Issue
Block a user