Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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);
}
};

Expand All @@ -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
Expand All @@ -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
await updateJobStatusTimestamp(id);

const range = (Date.now() - start) / 1000;
if (localJobStatus.status == JOB_STATUS.DONE) {
setPackingResults({
Expand Down
2 changes: 1 addition & 1 deletion src/constants/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions src/utils/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
doc,
Timestamp,
deleteDoc,
updateDoc
} from "firebase/firestore";
import { sortBy } from "lodash-es";
import {
Expand Down Expand Up @@ -125,6 +126,13 @@ const getJobStatus = async (
return docs[0] || undefined;
};

const updateJobStatusTimestamp = async (jobId: string) => {
const data = {
timestamp: Timestamp.now(),
};
await updateDoc(doc(db, FIRESTORE_COLLECTIONS.JOB_STATUS, jobId), data);
};

const getOutputsDirectory = async (jobId: string) => {
const querySnapshot = await queryDocumentById(
FIRESTORE_COLLECTIONS.JOB_STATUS,
Expand Down Expand Up @@ -274,4 +282,5 @@ export {
getRecipeManifestFromFirebase,
getRecipeDataFromFirebase,
getOutputsDirectory,
updateJobStatusTimestamp,
};