From 9e72abea39c86271f15d9ceccc87fa20a63cd310 Mon Sep 17 00:00:00 2001 From: ascibisz Date: Thu, 5 Feb 2026 09:30:03 -0800 Subject: [PATCH 1/2] set retention for job status to 30 days, update job status timestamp on read, and misc bug fixes --- src/App.tsx | 15 ++++++++++++--- src/constants/firebase.ts | 2 +- src/utils/firebase.ts | 10 ++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 37a21efa..ba7fcbc9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,6 @@ import { useState } from "react"; import { Layout, Typography } from "antd"; -import { getJobStatus } from "./utils/firebase"; +import { getJobStatus, updateJobStatusTimestamp } from "./utils/firebase"; import { getFirebaseRecipe, jsonToString } from "./utils/recipeLoader"; import { getSubmitPackingUrl, JOB_STATUS } from "./constants/aws"; import { @@ -68,14 +68,15 @@ function App() { start = Date.now(); const response = await fetch(request); setJobStatus(JOB_STATUS.SUBMITTED); - const data = await response.json(); if (response.ok) { + const data = await response.json(); setJobId(data.jobId); setJobStatus(JOB_STATUS.STARTING); return data.jobId; } else { + const errorText = await response.text(); setJobStatus(JOB_STATUS.FAILED); - setJobLogs(JSON.stringify(data)); + setJobLogs(errorText); } }; @@ -92,6 +93,9 @@ function App() { const checkStatus = async (jobIdFromSubmit: string) => { const id = jobIdFromSubmit || jobId; let localJobStatus = await getJobStatus(id); + if (localJobStatus) { + setJobStatus(localJobStatus.status); + } while ( localJobStatus?.status !== JOB_STATUS.DONE && localJobStatus?.status !== JOB_STATUS.FAILED @@ -106,6 +110,11 @@ function App() { setJobStatus(newJobStatus.status); } } + + // Update the job status timestamp after reading the final status to + // ensure we have the most recent timestamp for retention policy + updateJobStatusTimestamp(id); + const range = (Date.now() - start) / 1000; if (localJobStatus.status == JOB_STATUS.DONE) { setPackingResults({ diff --git a/src/constants/firebase.ts b/src/constants/firebase.ts index 7f5bff4f..a06200b8 100644 --- a/src/constants/firebase.ts +++ b/src/constants/firebase.ts @@ -44,7 +44,7 @@ export const FIRESTORE_FIELDS = { export const RETENTION_POLICY = { RETENTION_PERIODS: { RECIPES_EDITED: 24 * 60 * 60 * 1000, // 24 hours - JOB_STATUS: 24 * 60 * 60 * 1000, // 24 hours + JOB_STATUS: 30 * 24 * 60 * 60 * 1000, // 30 days }, TIMESTAMP_FIELD: "timestamp", diff --git a/src/utils/firebase.ts b/src/utils/firebase.ts index d6c630cd..c3faa452 100644 --- a/src/utils/firebase.ts +++ b/src/utils/firebase.ts @@ -11,6 +11,7 @@ import { doc, Timestamp, deleteDoc, + updateDoc } from "firebase/firestore"; import { sortBy } from "lodash-es"; import { @@ -125,6 +126,14 @@ const getJobStatus = async ( return docs[0] || undefined; }; +const updateJobStatusTimestamp = async (jobId: string) => { + const timestamp = Timestamp.now(); + const data = { + "timestamp": timestamp, + } + await updateDoc(doc(db, FIRESTORE_COLLECTIONS.JOB_STATUS, jobId), data); +}; + const getOutputsDirectory = async (jobId: string) => { const querySnapshot = await queryDocumentById( FIRESTORE_COLLECTIONS.JOB_STATUS, @@ -274,4 +283,5 @@ export { getRecipeManifestFromFirebase, getRecipeDataFromFirebase, getOutputsDirectory, + updateJobStatusTimestamp, }; From b6560f98a2aaf51370c68c650f9781f6758d9e81 Mon Sep 17 00:00:00 2001 From: ascibisz Date: Thu, 5 Feb 2026 10:20:19 -0800 Subject: [PATCH 2/2] code cleanup --- src/App.tsx | 2 +- src/utils/firebase.ts | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index ba7fcbc9..b3d8cf77 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -113,7 +113,7 @@ function App() { // Update the job status timestamp after reading the final status to // ensure we have the most recent timestamp for retention policy - updateJobStatusTimestamp(id); + await updateJobStatusTimestamp(id); const range = (Date.now() - start) / 1000; if (localJobStatus.status == JOB_STATUS.DONE) { diff --git a/src/utils/firebase.ts b/src/utils/firebase.ts index c3faa452..caf24d96 100644 --- a/src/utils/firebase.ts +++ b/src/utils/firebase.ts @@ -127,10 +127,9 @@ const getJobStatus = async ( }; const updateJobStatusTimestamp = async (jobId: string) => { - const timestamp = Timestamp.now(); const data = { - "timestamp": timestamp, - } + timestamp: Timestamp.now(), + }; await updateDoc(doc(db, FIRESTORE_COLLECTIONS.JOB_STATUS, jobId), data); };