Fix high priority pipeline issues

Implement orphaned image cleanup, temp refs cleanup, deadlock retry, and lock cleanup. These fixes address critical areas of data integrity, resource management, and system resilience within the submission pipeline.
This commit is contained in:
gpt-engineer-app[bot]
2025-11-06 18:54:47 +00:00
parent b92a62ebc8
commit 5c1fbced45
2 changed files with 59 additions and 23 deletions

View File

@@ -4,6 +4,7 @@ import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
import { createErrorResponse } from "../_shared/errorSanitizer.ts";
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
import { rateLimiters, withRateLimit } from "../_shared/rateLimiter.ts";
import { withEdgeRetry, isDeadlockError } from "../_shared/retryHelper.ts";
const corsHeaders = {
'Access-Control-Allow-Origin': '*',
@@ -1071,28 +1072,31 @@ serve(withRateLimit(async (req) => {
}> = [];
// Process items in order
for (const item of sortedItems) {
edgeLogger.info('Processing item', { action: 'approval_process_item', itemId: item.id, itemType: item.item_type });
// Extract data from relational tables based on item_type (OUTSIDE try-catch)
let itemData: any;
switch (item.item_type) {
case 'park':
itemData = {
...(item as any).park_submission,
// Merge temp refs for this item
...(tempRefsByItemId.get(item.id) || {})
};
// DEBUG: Log what columns are present
edgeLogger.info('Park item data loaded', {
action: 'approval_park_data_debug',
itemId: item.id,
hasLocationId: !!itemData.location_id,
parkSubmissionId: itemData.id,
parkSubmissionKeys: Object.keys((item as any).park_submission || {}),
requestId: tracking.requestId
});
break;
// Wrap entire approval loop in deadlock retry logic
await withEdgeRetry(
async () => {
for (const item of sortedItems) {
edgeLogger.info('Processing item', { action: 'approval_process_item', itemId: item.id, itemType: item.item_type });
// Extract data from relational tables based on item_type (OUTSIDE try-catch)
let itemData: any;
switch (item.item_type) {
case 'park':
itemData = {
...(item as any).park_submission,
// Merge temp refs for this item
...(tempRefsByItemId.get(item.id) || {})
};
// DEBUG: Log what columns are present
edgeLogger.info('Park item data loaded', {
action: 'approval_park_data_debug',
itemId: item.id,
hasLocationId: !!itemData.location_id,
parkSubmissionId: itemData.id,
parkSubmissionKeys: Object.keys((item as any).park_submission || {}),
requestId: tracking.requestId
});
break;
case 'ride':
itemData = {
...(item as any).ride_submission,
@@ -1583,6 +1587,18 @@ serve(withRateLimit(async (req) => {
if (updateError) {
edgeLogger.error('Failed to update submission status', { action: 'approval_update_status', error: updateError.message, requestId: tracking.requestId });
}
},
{
maxAttempts: 3,
baseDelay: 500,
maxDelay: 2000,
backoffMultiplier: 2,
jitter: true,
shouldRetry: isDeadlockError
},
tracking.requestId,
'approval_transaction'
);
// Log audit trail for submission action
try {