Update to add purger
This commit is contained in:
parent
67ba524b2d
commit
5949d140af
19
src/index.ts
19
src/index.ts
@ -15,7 +15,8 @@ const RAIN_GAUGE_ENDPOINT = process.env.RAIN_GAUGE_ENDPOINT;
|
|||||||
const SOIL_SENSOR_ENDPOINT = process.env.SOIL_SENSOR_ENDPOINT;
|
const SOIL_SENSOR_ENDPOINT = process.env.SOIL_SENSOR_ENDPOINT;
|
||||||
const TEASENSE_ENDPOINT = process.env.TEASENSE_ENDPOINT;
|
const TEASENSE_ENDPOINT = process.env.TEASENSE_ENDPOINT;
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
const RAIN_GAUGE_SLEEP = 100;
|
const DATA_COLLECT_SLEEP = 100;
|
||||||
|
const PURGE_SLEEP = 60000;
|
||||||
|
|
||||||
mongoose.connect(process.env.DB_URL ?? '');
|
mongoose.connect(process.env.DB_URL ?? '');
|
||||||
|
|
||||||
@ -112,7 +113,17 @@ const collectData = async () => {
|
|||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setTimeout(() => collectData(), RAIN_GAUGE_SLEEP);
|
setTimeout(() => collectData(), DATA_COLLECT_SLEEP);
|
||||||
}
|
};
|
||||||
|
|
||||||
setTimeout(() => collectData(), RAIN_GAUGE_SLEEP);
|
const purger = async () => {
|
||||||
|
const startTime = subHours(new Date(), 24);
|
||||||
|
await DataModel.deleteMany({
|
||||||
|
timestamp: {
|
||||||
|
$lt: startTime,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
setTimeout(() => collectData(), DATA_COLLECT_SLEEP);
|
||||||
|
setInterval(() => purger(), PURGE_SLEEP);
|
Loading…
Reference in New Issue
Block a user