mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 15:31:13 -05:00
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.
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
|
import { createEdgeFunction } from '../_shared/edgeFunctionWrapper.ts';
|
|
import { edgeLogger } from '../_shared/logger.ts';
|
|
|
|
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) {
|
|
edgeLogger.error('Error running data retention cleanup', {
|
|
error,
|
|
requestId: context.requestId
|
|
});
|
|
throw error;
|
|
}
|
|
|
|
edgeLogger.info('Data retention cleanup completed', {
|
|
results: data,
|
|
requestId: context.requestId
|
|
});
|
|
|
|
return new Response(
|
|
JSON.stringify({
|
|
success: true,
|
|
cleanup_results: data.cleanup_results,
|
|
timestamp: data.timestamp,
|
|
}),
|
|
{ headers: { 'Content-Type': 'application/json' } }
|
|
);
|
|
}
|
|
);
|