diff --git a/backend/migrations/089_immutable_schedules.sql b/backend/migrations/089_immutable_schedules.sql index 624cda69..e477d9e9 100644 --- a/backend/migrations/089_immutable_schedules.sql +++ b/backend/migrations/089_immutable_schedules.sql @@ -24,11 +24,11 @@ SET interval_hours = 168, -- 7 days is_immutable = TRUE, method = 'http', description = 'Discover new Dutchie stores weekly (HTTP transport)' -WHERE name = 'store_discovery_dutchie'; +WHERE name IN ('store_discovery_dutchie', 'Store Discovery'); -- Insert if doesn't exist INSERT INTO task_schedules (name, role, interval_hours, priority, description, is_immutable, method, platform, next_run_at) -VALUES ('store_discovery_dutchie', 'store_discovery', 168, 5, 'Discover new Dutchie stores weekly (HTTP transport)', TRUE, 'http', 'dutchie', NOW()) +VALUES ('Store Discovery', 'store_discovery', 168, 5, 'Discover new Dutchie stores weekly (HTTP transport)', TRUE, 'http', 'dutchie', NOW()) ON CONFLICT (name) DO UPDATE SET interval_hours = 168, is_immutable = TRUE, diff --git a/backend/migrations/106_rename_store_discovery_schedule.sql b/backend/migrations/106_rename_store_discovery_schedule.sql new file mode 100644 index 00000000..4394ae3e --- /dev/null +++ b/backend/migrations/106_rename_store_discovery_schedule.sql @@ -0,0 +1,10 @@ +-- Migration: 106_rename_store_discovery_schedule.sql +-- Description: Rename store_discovery_dutchie to 'Store Discovery' +-- Created: 2025-12-13 + +-- Update the schedule name for better display +-- The platform='dutchie' field is preserved for badge display in UI +UPDATE task_schedules +SET name = 'Store Discovery', + updated_at = NOW() +WHERE name = 'store_discovery_dutchie'; diff --git a/backend/src/services/task-scheduler.ts b/backend/src/services/task-scheduler.ts index 9ec913c0..d2103ff4 100644 --- a/backend/src/services/task-scheduler.ts +++ b/backend/src/services/task-scheduler.ts @@ -99,7 +99,7 @@ class TaskScheduler { // Core schedules - all use HTTP transport for browser-based scraping const defaults = [ { - name: 'store_discovery_dutchie', + name: 'Store Discovery', role: 'store_discovery' as TaskRole, interval_hours: 168, // Weekly priority: 5, diff --git a/backend/src/tasks/handlers/store-discovery-http.ts b/backend/src/tasks/handlers/store-discovery-http.ts index 22fb0343..94b50078 100644 --- a/backend/src/tasks/handlers/store-discovery-http.ts +++ b/backend/src/tasks/handlers/store-discovery-http.ts @@ -438,7 +438,50 @@ export async function handleStoreDiscoveryHttp(ctx: TaskContext): Promise 0) { + console.log(`[StoreDiscoveryHTTP] Self-healing: Found ${healResult.rows.length} stores missing payloads`); + + for (const store of healResult.rows) { + await pool.query(` + INSERT INTO task_queue (role, dispensary_id, priority, scheduled_for, method, platform) + VALUES ('product_discovery', $1, 5, NOW(), 'http', 'dutchie') + ON CONFLICT DO NOTHING + `, [store.id]); + healedStoreIds.push(store.id); + } + + console.log(`[StoreDiscoveryHTTP] Self-healing: Queued ${healedStoreIds.length} product_discovery tasks`); + } + } catch (healErr: any) { + console.error(`[StoreDiscoveryHTTP] Self-healing error:`, healErr.message); + } + + console.log(`[StoreDiscoveryHTTP] Complete: ${totalDiscovered} new, ${totalUpserted} upserted, ${allNewStoreIds.length} promoted, ${healedStoreIds.length} healed`); return { success: true, @@ -446,6 +489,7 @@ export async function handleStoreDiscoveryHttp(ctx: TaskContext): Promise