Simplify calendar cleanup: handle in SQL function, remove HTTP dependency
Due to Docker networking limitations between supabase-db and supabase-edge-functions containers, automatic HTTP triggering of the edge function is not possible. Changes: - Updated cancel_expired_consulting_orders_sql() to also clear calendar_event_id - This prevents stale references in the database - Removed Task 2 dependency documentation (not workable without HTTP access) - Edge function trigger-calendar-cleanup still available for manual triggering To manually clean up Google Calendar events: curl -X POST https://your-project.supabase.co/functions/v1/trigger-calendar-cleanup Coolify Tasks: - Task 1: Keep (works fine with psql) - Task 2: DELETE (HTTP between containers doesn't work) - Task 3: DELETE (deprecated duplicate) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ DECLARE
|
||||
expired_order RECORD;
|
||||
expired_session RECORD;
|
||||
processed_count INTEGER := 0;
|
||||
calendar_cleanup_count INTEGER := 0;
|
||||
BEGIN
|
||||
-- Log start
|
||||
RAISE NOTICE '[CANCEL-EXPIRED] Starting check for expired consulting orders';
|
||||
@@ -57,6 +58,16 @@ BEGIN
|
||||
DELETE FROM consulting_time_slots
|
||||
WHERE session_id = expired_session.id;
|
||||
|
||||
-- Clear calendar_event_id to mark for cleanup
|
||||
-- Note: The actual Google Calendar event deletion is handled separately
|
||||
-- via the trigger-calendar-cleanup edge function (if HTTP access is available)
|
||||
IF expired_session.calendar_event_id IS NOT NULL THEN
|
||||
UPDATE consulting_sessions
|
||||
SET calendar_event_id = NULL
|
||||
WHERE id = expired_session.id;
|
||||
calendar_cleanup_count := calendar_cleanup_count + 1;
|
||||
END IF;
|
||||
|
||||
RAISE NOTICE '[CANCEL-EXPIRED] Cancelled session: %', expired_session.id;
|
||||
END LOOP;
|
||||
|
||||
@@ -68,7 +79,8 @@ BEGIN
|
||||
RETURN jsonb_build_object(
|
||||
'success', true,
|
||||
'processed', processed_count,
|
||||
'message', format('Successfully cancelled %s expired consulting orders', processed_count)
|
||||
'calendar_references_cleared', calendar_cleanup_count,
|
||||
'message', format('Successfully cancelled %s expired consulting orders (cleared %s calendar references)', processed_count, calendar_cleanup_count)
|
||||
);
|
||||
END;
|
||||
$$;
|
||||
@@ -86,14 +98,18 @@ $$;
|
||||
-- Timeout: 30 seconds
|
||||
-- Container: supabase-db (or supabase-rest if it has psql client)
|
||||
--
|
||||
-- Task 2: Calendar Cleanup (every 15 minutes)
|
||||
-- NOTE: Calendar cleanup is now included in the SQL function above.
|
||||
-- The function clears calendar_event_id references to prevent stale data.
|
||||
-- Actual Google Calendar event deletion can be triggered manually via:
|
||||
-- curl -X POST http://your-domain/functions/v1/trigger-calendar-cleanup
|
||||
--
|
||||
-- Task 2 (DEPRECATED): Calendar cleanup edge function
|
||||
-- -------------------------------------------
|
||||
-- Name: cancel-expired-consulting-orders-calendar
|
||||
-- Command: curl -X POST http://supabase-edge-functions:8000/functions/v1/trigger-calendar-cleanup
|
||||
-- Alternative: wget -qO- --post-data='' http://supabase-edge-functions:8000/functions/v1/trigger-calendar-cleanup
|
||||
-- Frequency: */15 * * * *
|
||||
-- Timeout: 30 seconds
|
||||
-- Container: supabase-db (IMPORTANT: Must run on supabase-db service which has curl/wget)
|
||||
-- Due to Docker networking limitations between containers, we cannot
|
||||
-- automatically trigger the edge function from the scheduled task.
|
||||
-- The SQL function now handles cleanup of database references.
|
||||
-- To manually clean up Google Calendar events, trigger the edge function:
|
||||
-- POST http://your-supabase-project.supabase.co/functions/v1/trigger-calendar-cleanup
|
||||
|
||||
-- ============================================
|
||||
-- Manual Testing
|
||||
|
||||
Reference in New Issue
Block a user