mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:31:11 -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.
56 lines
1.7 KiB
TypeScript
56 lines
1.7 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';
|
|
import { formatEdgeError } from '../_shared/errorFormatter.ts';
|
|
|
|
export default createEdgeFunction(
|
|
{
|
|
name: 'scheduled-maintenance',
|
|
requireAuth: false,
|
|
},
|
|
async (req, context, supabase) => {
|
|
edgeLogger.info('Starting scheduled maintenance', {
|
|
requestId: context.requestId
|
|
});
|
|
|
|
// Run system maintenance (orphaned image cleanup)
|
|
const { data: maintenanceData, error: maintenanceError } = await supabase.rpc('run_system_maintenance');
|
|
|
|
if (maintenanceError) {
|
|
edgeLogger.error('Maintenance failed', {
|
|
error: maintenanceError.message,
|
|
requestId: context.requestId
|
|
});
|
|
} else {
|
|
edgeLogger.info('Maintenance completed', {
|
|
result: maintenanceData,
|
|
requestId: context.requestId
|
|
});
|
|
}
|
|
|
|
// Run pipeline monitoring checks
|
|
const { data: monitoringData, error: monitoringError } = await supabase.rpc('run_pipeline_monitoring');
|
|
|
|
if (monitoringError) {
|
|
edgeLogger.error('Pipeline monitoring failed', {
|
|
error: monitoringError.message,
|
|
requestId: context.requestId
|
|
});
|
|
} else {
|
|
edgeLogger.info('Pipeline monitoring completed', {
|
|
result: monitoringData,
|
|
requestId: context.requestId
|
|
});
|
|
}
|
|
|
|
return new Response(
|
|
JSON.stringify({
|
|
success: true,
|
|
maintenance: maintenanceData,
|
|
monitoring: monitoringData,
|
|
}),
|
|
{ headers: { 'Content-Type': 'application/json' } }
|
|
);
|
|
}
|
|
);
|