Skip to content

Commit 0a99316

Browse files
committed
move pruning old versions to beginning of update, make number of versions to keep configurable as KEEP_VERSIONS
1 parent 69b58b0 commit 0a99316

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

task/StorageCleanup.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ function isCorrectRouter(basePath, file, routerId) {
4343
}
4444

4545
/*
46-
* Keeps 10 valid latest versions and removes the rest.
46+
* Keeps KEEP_VERSIONS (default 10) valid latest versions and removes the rest.
4747
*/
4848
function deleteOldVersions(sourceDir, routerId, tag) {
49+
const savedCount = process.env.KEEP_VERSIONS ?? '10';
4950
const basePath = `${sourceDir}/${tag}`;
5051
if (!fs.existsSync(basePath)) {
5152
return Promise(res => res());
@@ -55,7 +56,7 @@ function deleteOldVersions(sourceDir, routerId, tag) {
5556
.readdirSync(basePath)
5657
.filter(file => isCorrectRouter(basePath, file, routerId))
5758
.sort(sortByDate)
58-
.slice(0, -10);
59+
.slice(0, -savedCount);
5960
return filesToDelete.map(file => del(`${basePath}/${file}/${routerId}`));
6061
});
6162
}

task/Update.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ async function handleCleanup() {
139139
* This function only builds the street graph with OSM and DEM data.
140140
*/
141141
async function buildStreetOnlyGraph(name) {
142+
await handleCleanup();
143+
142144
await handleSeeding();
143145

144146
await handleOsmAndDemUpdate();
@@ -174,6 +176,8 @@ async function buildStreetOnlyGraph(name) {
174176
* This function does the whole build.
175177
*/
176178
async function buildGraph(name) {
179+
await handleCleanup();
180+
177181
await handleSeeding();
178182

179183
await handleOsmAndDemUpdate();
@@ -201,8 +205,6 @@ async function buildGraph(name) {
201205

202206
buildAndDeployDockerImages(date);
203207

204-
await handleCleanup();
205-
206208
if (global.hasFailures) {
207209
updateSlackMessage(
208210
`${name} data updated, but partially falling back to older data :boom:`,
@@ -216,6 +218,8 @@ async function buildGraph(name) {
216218
* This function builds the graph from prebuilt street graph data.
217219
*/
218220
async function buildWithPrebuiltStreetGraph(name) {
221+
await handleCleanup();
222+
219223
await handleSeeding();
220224

221225
await start('gtfs:update');
@@ -241,8 +245,6 @@ async function buildWithPrebuiltStreetGraph(name) {
241245

242246
buildAndDeployDockerImages(date);
243247

244-
await handleCleanup();
245-
246248
if (global.hasFailures) {
247249
updateSlackMessage(
248250
`${name} data updated from prebuilt street only graph, but partially falling back to older data :boom:`,

0 commit comments

Comments
 (0)