Skip to content

Commit

Permalink
dump observation data into s3 every hour + monitor it in sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
khavinshankar committed Nov 24, 2023
1 parent 1d1383c commit ba649b7
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 167 deletions.
209 changes: 72 additions & 137 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"dependencies": {
"@prisma/client": "^4.15.0",
"@sentry/node": "^6.17.7",
"@sentry/tracing": "^6.17.7",
"@sentry/node": "^7.81.1",
"@sentry/tracing": "^7.81.1",
"aws-sdk": "^2.1408.0",
"axios": "^0.26.1",
"connect-flash": "^0.1.1",
Expand Down Expand Up @@ -70,6 +70,6 @@
"typescript": "^5.2.2"
},
"_moduleAliases": {
"@": "dist/src"
"@": "src"
}
}
37 changes: 31 additions & 6 deletions src/controller/ObservationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var logData: {
}[] = [];
var statusData: ObservationStatus[] = [];
var lastObservationData: LastObservationData = {};
let observationData: { time: Date; data: Observation[][] }[] = [];

// start updating after 1 minutes of starting the middleware
let lastUpdatedToCare = new Date().getTime() - 59 * 60 * 1000;
Expand All @@ -45,10 +46,30 @@ let lastUpdatedToCare = new Date().getTime() - 59 * 60 * 1000;

// Update Interval is set to 1 hour
const UPDATE_INTERVAL = 60 * 60 * 1000;
const S3_DATA_DUMP_INTERVAL = 1000 * 60 * 60;
// For testing purposes, set update interval to 5 minutes
// const UPDATE_INTERVAL = 5 * 60 * 1000;
const DEFAULT_LISTING_LIMIT = 10;

setInterval(() => {
makeDataDumpToJson(
observationData,
`observations/${new Date().getTime()}.json`,
{
slug: "s3_observations_dump",
options: {
schedule: {
type: "interval",
unit: "minutes",
value: S3_DATA_DUMP_INTERVAL / (1000 * 60),
},
},
}
);

observationData = [];
}, S3_DATA_DUMP_INTERVAL);

const getTime = (date: string) =>
new Date(date.replace(" ", "T").concat("+0530"));

Expand Down Expand Up @@ -350,12 +371,15 @@ const updateObservationsToCare = async () => {
monitorPreset
);
await makeDataDumpToJson(
payload,
v2Payload,
asset.externalId,
patient_id,
consultation_id,
b64Image
{
payload,
v2Payload,
assetExternalId: asset.externalId,
patient_id,
consultation_id,
b64Image,
},
`${asset.externalId}--${new Date().getTime()}.json`
);
} catch (err) {
console.log("updateObservationsToCare:Data dump failed", err);
Expand Down Expand Up @@ -504,6 +528,7 @@ export class ObservationController {
addLogData(req.body);
addStatusData(req.body);
const observations = req.body;
observationData.push({ time: new Date(), data: observations });
// If req.body.observations is an array, then we need to loop through it and create a new observation for each one
// If req.body.observations is a single object, then we need to create a new observation for it
// If req.body.observations is undefined, then we need to return an error
Expand Down
Loading

0 comments on commit ba649b7

Please sign in to comment.