feat: max retries for failure

This commit is contained in:
karishmas6
2024-09-19 18:14:56 +05:30
parent f6a7f5582c
commit 871a9b88bd

View File

@@ -8,9 +8,12 @@ import { readFile } from "../storage";
interface GoogleSheetUpdateTask { interface GoogleSheetUpdateTask {
name: string; name: string;
runId: string; runId: string;
status: 'pending' | 'completed'; status: 'pending' | 'completed' | 'failed';
retries: number;
} }
const MAX_RETRIES = 5;
export let googleSheetUpdateTasks: { [runId: string]: GoogleSheetUpdateTask } = {}; export let googleSheetUpdateTasks: { [runId: string]: GoogleSheetUpdateTask } = {};
@@ -103,6 +106,12 @@ const processGoogleSheetUpdates = async () => {
console.log(`Successfully updated Google Sheets for run ${task.runId}`); console.log(`Successfully updated Google Sheets for run ${task.runId}`);
delete googleSheetUpdateTasks[runId]; delete googleSheetUpdateTasks[runId];
} catch (error: any) { } catch (error: any) {
if (task.retries < MAX_RETRIES) {
googleSheetUpdateTasks[runId].retries += 1;
} else {
// Mark as failed after maximum retries
googleSheetUpdateTasks[runId].status = 'failed';
}
console.error(`Failed to update Google Sheets for run ${task.runId}:`, error); console.error(`Failed to update Google Sheets for run ${task.runId}:`, error);
} }
} }