Browse Source

fix: add is_active filter and debug logging to woocommerce-scheduled-sync #71

Claude 5 months ago
parent
commit
9f80104a5e
1 changed files with 18 additions and 1 deletions
  1. 18 1
      supabase/functions/woocommerce-scheduled-sync/index.ts

+ 18 - 1
supabase/functions/woocommerce-scheduled-sync/index.ts

@@ -69,6 +69,7 @@ serve(wrapHandler('woocommerce-scheduled-sync', async (req) => {
         )
       `)
       .eq('platform_name', 'woocommerce')
+      .eq('is_active', true)
 
     // If specific frequency requested, filter by it
     if (frequency !== 'all') {
@@ -85,21 +86,37 @@ serve(wrapHandler('woocommerce-scheduled-sync', async (req) => {
       )
     }
 
+    console.log(`[WooCommerce Scheduled Sync] Fetched ${stores?.length || 0} WooCommerce stores from database`)
+
     // Filter stores that have sync enabled and are due for sync
     const now = new Date()
     const storesToSync = stores?.filter(store => {
       const config = store.store_sync_config?.[0]
+
+      // Debug logging
+      console.log(`[WooCommerce Scheduled Sync] Checking store ${store.id}:`, {
+        has_config: !!config,
+        enabled: config?.enabled,
+        next_sync_at: config?.next_sync_at,
+        is_array: Array.isArray(store.store_sync_config),
+        config_length: store.store_sync_config?.length
+      })
+
       if (!config || !config.enabled) {
+        console.log(`[WooCommerce Scheduled Sync] Store ${store.id} filtered out: no config or disabled`)
         return false
       }
 
       // Check if sync is due
       if (config.next_sync_at) {
         const nextSync = new Date(config.next_sync_at)
-        return nextSync <= now
+        const isDue = nextSync <= now
+        console.log(`[WooCommerce Scheduled Sync] Store ${store.id} next sync: ${config.next_sync_at}, is due: ${isDue}`)
+        return isDue
       }
 
       // If no next_sync_at, sync is due
+      console.log(`[WooCommerce Scheduled Sync] Store ${store.id} has no next_sync_at, sync is due`)
       return true
     }) || []