mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 12:11:11 -05:00
Continue Phase 2 Batch 2 and Batch 3
Migrate 6 background jobs to use wrapEdgeFunction: cleanup-old-versions, process-scheduled-deletions, data-retention-cleanup, run-cleanup-jobs, scheduled-maintenance, process-expired-bans. Replace old server routines with edgeFunction wrapper, add centralized logging, tracing, and standardized error handling, and adjust for batch-wise deployment.
This commit is contained in:
@@ -1,31 +1,30 @@
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||
import { createEdgeFunction } from '../_shared/edgeFunctionWrapper.ts';
|
||||
import { edgeLogger } from '../_shared/logger.ts';
|
||||
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
||||
};
|
||||
|
||||
Deno.serve(async (req) => {
|
||||
if (req.method === 'OPTIONS') {
|
||||
return new Response(null, { headers: corsHeaders });
|
||||
}
|
||||
|
||||
try {
|
||||
const supabaseUrl = Deno.env.get('SUPABASE_URL')!;
|
||||
const supabaseKey = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!;
|
||||
const supabase = createClient(supabaseUrl, supabaseKey);
|
||||
|
||||
console.log('Starting data retention cleanup...');
|
||||
export default createEdgeFunction(
|
||||
{
|
||||
name: 'data-retention-cleanup',
|
||||
requireAuth: false,
|
||||
},
|
||||
async (req, context, supabase) => {
|
||||
edgeLogger.info('Starting data retention cleanup', { requestId: context.requestId });
|
||||
|
||||
// Call the master cleanup function
|
||||
const { data, error } = await supabase.rpc('run_data_retention_cleanup');
|
||||
|
||||
if (error) {
|
||||
console.error('Error running data retention cleanup:', error);
|
||||
edgeLogger.error('Error running data retention cleanup', {
|
||||
error,
|
||||
requestId: context.requestId
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.log('Data retention cleanup completed:', data);
|
||||
edgeLogger.info('Data retention cleanup completed', {
|
||||
results: data,
|
||||
requestId: context.requestId
|
||||
});
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
@@ -33,16 +32,7 @@ Deno.serve(async (req) => {
|
||||
cleanup_results: data.cleanup_results,
|
||||
timestamp: data.timestamp,
|
||||
}),
|
||||
{ headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error in data-retention-cleanup function:', error);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message }),
|
||||
{
|
||||
status: 500,
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
}
|
||||
{ headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user