mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 11:11:14 -05:00
feat: Implement retry logic and tracking
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||
import { withEdgeRetry } from '../_shared/retryHelper.ts';
|
||||
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
@@ -150,22 +151,32 @@ serve(async (req) => {
|
||||
|
||||
edgeLogger.info('Triggering notification with payload', { action: 'notify_moderators_report', requestId: tracking.requestId });
|
||||
|
||||
// Invoke the trigger-notification function
|
||||
const { data: result, error: notifyError } = await supabase.functions.invoke(
|
||||
'trigger-notification',
|
||||
{
|
||||
body: {
|
||||
workflowId: template.workflow_id,
|
||||
topicKey: 'moderation-reports',
|
||||
payload: notificationPayload,
|
||||
},
|
||||
}
|
||||
);
|
||||
// Invoke the trigger-notification function with retry
|
||||
const result = await withEdgeRetry(
|
||||
async () => {
|
||||
const { data, error } = await supabase.functions.invoke(
|
||||
'trigger-notification',
|
||||
{
|
||||
body: {
|
||||
workflowId: template.workflow_id,
|
||||
topicKey: 'moderation-reports',
|
||||
payload: notificationPayload,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (notifyError) {
|
||||
edgeLogger.error('Error triggering notification', { action: 'notify_moderators_report', requestId: tracking.requestId, error: notifyError });
|
||||
throw notifyError;
|
||||
}
|
||||
if (error) {
|
||||
const enhancedError = new Error(error.message || 'Notification trigger failed');
|
||||
(enhancedError as any).status = error.status;
|
||||
throw enhancedError;
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
{ maxAttempts: 3, baseDelay: 1000 },
|
||||
tracking.requestId,
|
||||
'trigger-report-notification'
|
||||
);
|
||||
|
||||
edgeLogger.info('Notification triggered successfully', { action: 'notify_moderators_report', requestId: tracking.requestId, result });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user