mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-29 22:47:06 -05:00
Compare commits
3 Commits
d56bb3cd15
...
3797e34e0b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3797e34e0b | ||
|
|
0e9ea18be8 | ||
|
|
10df39c7d4 |
@@ -91,3 +91,12 @@ verify_jwt = true
|
|||||||
|
|
||||||
[functions.monitor-rate-limits]
|
[functions.monitor-rate-limits]
|
||||||
verify_jwt = false
|
verify_jwt = false
|
||||||
|
|
||||||
|
[functions.backfill-park-locations]
|
||||||
|
verify_jwt = true
|
||||||
|
|
||||||
|
[functions.backfill-ride-data]
|
||||||
|
verify_jwt = true
|
||||||
|
|
||||||
|
[functions.backfill-company-data]
|
||||||
|
verify_jwt = true
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Prevents sensitive data exposure and provides consistent log format
|
* Prevents sensitive data exposure and provides consistent log format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createClient } from 'jsr:@supabase/supabase-js@2';
|
import { createClient } from '@supabase/supabase-js';
|
||||||
import { formatEdgeError } from './errorFormatter.ts';
|
import { formatEdgeError } from './errorFormatter.ts';
|
||||||
|
|
||||||
type LogLevel = 'info' | 'warn' | 'error' | 'debug';
|
type LogLevel = 'info' | 'warn' | 'error' | 'debug';
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import { createEdgeFunction } from '../_shared/edgeFunctionWrapper.ts';
|
import { createEdgeFunction } from '../_shared/edgeFunctionWrapper.ts';
|
||||||
import { edgeLogger } from '../_shared/logger.ts';
|
import { edgeLogger } from '../_shared/logger.ts';
|
||||||
|
import { withEdgeRetry, isRetryableError, isDeadlockError } from '../_shared/retryHelper.ts';
|
||||||
|
import { corsHeadersWithMethods } from '../_shared/cors.ts';
|
||||||
|
|
||||||
export default createEdgeFunction(
|
export default createEdgeFunction(
|
||||||
{
|
{
|
||||||
name: 'backfill-company-data',
|
name: 'backfill-company-data',
|
||||||
requireAuth: true,
|
requireAuth: true,
|
||||||
|
corsHeaders: corsHeadersWithMethods,
|
||||||
},
|
},
|
||||||
async (req, context, supabase) => {
|
async (req, context, supabase) => {
|
||||||
edgeLogger.info('Starting company data backfill', { requestId: context.requestId });
|
edgeLogger.info('Starting company data backfill', { requestId: context.requestId });
|
||||||
@@ -23,20 +26,28 @@ export default createEdgeFunction(
|
|||||||
});
|
});
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({ error: 'Unauthorized: Superuser access required' }),
|
JSON.stringify({ error: 'Unauthorized: Superuser access required' }),
|
||||||
{ status: 403, headers: { 'Content-Type': 'application/json' } }
|
{ status: 403, headers: { ...corsHeadersWithMethods, 'Content-Type': 'application/json' } }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the backfill function
|
// Execute the backfill function with retry logic
|
||||||
const { data, error } = await supabase.rpc('backfill_company_data');
|
const { data, error } = await withEdgeRetry(
|
||||||
|
async () => {
|
||||||
if (error) {
|
const result = await supabase.rpc('backfill_company_data');
|
||||||
edgeLogger.error('Error running company data backfill', {
|
if (result.error) throw result.error;
|
||||||
error,
|
return result;
|
||||||
requestId: context.requestId
|
},
|
||||||
});
|
{
|
||||||
throw error;
|
maxAttempts: 5,
|
||||||
}
|
baseDelay: 2000,
|
||||||
|
maxDelay: 30000,
|
||||||
|
backoffMultiplier: 2,
|
||||||
|
jitter: true,
|
||||||
|
shouldRetry: (error) => isRetryableError(error) || isDeadlockError(error)
|
||||||
|
},
|
||||||
|
context.requestId,
|
||||||
|
'backfill_company_data'
|
||||||
|
);
|
||||||
|
|
||||||
edgeLogger.info('Company data backfill completed', {
|
edgeLogger.info('Company data backfill completed', {
|
||||||
results: data,
|
results: data,
|
||||||
@@ -48,7 +59,7 @@ export default createEdgeFunction(
|
|||||||
success: true,
|
success: true,
|
||||||
...data,
|
...data,
|
||||||
}),
|
}),
|
||||||
{ headers: { 'Content-Type': 'application/json' } }
|
{ headers: { ...corsHeadersWithMethods, 'Content-Type': 'application/json' } }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { createEdgeFunction } from '../_shared/edgeFunctionWrapper.ts';
|
import { createEdgeFunction } from '../_shared/edgeFunctionWrapper.ts';
|
||||||
import { edgeLogger } from '../_shared/logger.ts';
|
import { edgeLogger } from '../_shared/logger.ts';
|
||||||
import { corsHeadersWithMethods } from '../_shared/cors.ts';
|
import { corsHeadersWithMethods } from '../_shared/cors.ts';
|
||||||
|
import { withEdgeRetry, isRetryableError, isDeadlockError } from '../_shared/retryHelper.ts';
|
||||||
|
|
||||||
export default createEdgeFunction(
|
export default createEdgeFunction(
|
||||||
{
|
{
|
||||||
@@ -29,16 +30,24 @@ export default createEdgeFunction(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the backfill function
|
// Execute the backfill function with retry logic
|
||||||
const { data, error } = await supabase.rpc('backfill_park_locations');
|
const { data, error } = await withEdgeRetry(
|
||||||
|
async () => {
|
||||||
if (error) {
|
const result = await supabase.rpc('backfill_park_locations');
|
||||||
edgeLogger.error('Error running park location backfill', {
|
if (result.error) throw result.error;
|
||||||
error,
|
return result;
|
||||||
requestId: context.requestId
|
},
|
||||||
});
|
{
|
||||||
throw error;
|
maxAttempts: 5,
|
||||||
}
|
baseDelay: 2000,
|
||||||
|
maxDelay: 30000,
|
||||||
|
backoffMultiplier: 2,
|
||||||
|
jitter: true,
|
||||||
|
shouldRetry: (error) => isRetryableError(error) || isDeadlockError(error)
|
||||||
|
},
|
||||||
|
context.requestId,
|
||||||
|
'backfill_park_locations'
|
||||||
|
);
|
||||||
|
|
||||||
edgeLogger.info('Park location backfill completed', {
|
edgeLogger.info('Park location backfill completed', {
|
||||||
results: data,
|
results: data,
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import { createEdgeFunction } from '../_shared/edgeFunctionWrapper.ts';
|
import { createEdgeFunction } from '../_shared/edgeFunctionWrapper.ts';
|
||||||
import { edgeLogger } from '../_shared/logger.ts';
|
import { edgeLogger } from '../_shared/logger.ts';
|
||||||
|
import { withEdgeRetry, isRetryableError, isDeadlockError } from '../_shared/retryHelper.ts';
|
||||||
|
import { corsHeadersWithMethods } from '../_shared/cors.ts';
|
||||||
|
|
||||||
export default createEdgeFunction(
|
export default createEdgeFunction(
|
||||||
{
|
{
|
||||||
name: 'backfill-ride-data',
|
name: 'backfill-ride-data',
|
||||||
requireAuth: true,
|
requireAuth: true,
|
||||||
|
corsHeaders: corsHeadersWithMethods,
|
||||||
},
|
},
|
||||||
async (req, context, supabase) => {
|
async (req, context, supabase) => {
|
||||||
edgeLogger.info('Starting ride data backfill', { requestId: context.requestId });
|
edgeLogger.info('Starting ride data backfill', { requestId: context.requestId });
|
||||||
@@ -23,20 +26,28 @@ export default createEdgeFunction(
|
|||||||
});
|
});
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({ error: 'Unauthorized: Superuser access required' }),
|
JSON.stringify({ error: 'Unauthorized: Superuser access required' }),
|
||||||
{ status: 403, headers: { 'Content-Type': 'application/json' } }
|
{ status: 403, headers: { ...corsHeadersWithMethods, 'Content-Type': 'application/json' } }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the backfill function
|
// Execute the backfill function with retry logic
|
||||||
const { data, error } = await supabase.rpc('backfill_ride_data');
|
const { data, error } = await withEdgeRetry(
|
||||||
|
async () => {
|
||||||
if (error) {
|
const result = await supabase.rpc('backfill_ride_data');
|
||||||
edgeLogger.error('Error running ride data backfill', {
|
if (result.error) throw result.error;
|
||||||
error,
|
return result;
|
||||||
requestId: context.requestId
|
},
|
||||||
});
|
{
|
||||||
throw error;
|
maxAttempts: 5,
|
||||||
}
|
baseDelay: 2000,
|
||||||
|
maxDelay: 30000,
|
||||||
|
backoffMultiplier: 2,
|
||||||
|
jitter: true,
|
||||||
|
shouldRetry: (error) => isRetryableError(error) || isDeadlockError(error)
|
||||||
|
},
|
||||||
|
context.requestId,
|
||||||
|
'backfill_ride_data'
|
||||||
|
);
|
||||||
|
|
||||||
edgeLogger.info('Ride data backfill completed', {
|
edgeLogger.info('Ride data backfill completed', {
|
||||||
results: data,
|
results: data,
|
||||||
@@ -48,7 +59,7 @@ export default createEdgeFunction(
|
|||||||
success: true,
|
success: true,
|
||||||
...data,
|
...data,
|
||||||
}),
|
}),
|
||||||
{ headers: { 'Content-Type': 'application/json' } }
|
{ headers: { ...corsHeadersWithMethods, 'Content-Type': 'application/json' } }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user