Skip to content

Commit f5bab32

Browse files
authored
[server] Log ticks of periodic db deleter (#17089)
* [server] Log ticks of periodic db deleter * fix * fix * fix
1 parent 60ac0e4 commit f5bab32

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

components/gitpod-db/src/periodic-deleter.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,50 @@ export class PeriodicDbDeleter {
1717
@inject(TypeORM) protected readonly typeORM: TypeORM;
1818

1919
start() {
20-
log.error("[PeriodicDbDeleter] Start ...");
20+
log.info("[PeriodicDbDeleter] Start ...");
2121
this.sync().catch((err) => log.error("[PeriodicDbDeleter] sync failed", err));
2222
}
2323

2424
protected async sync() {
2525
const doSync = async () => {
26+
const tickID = new Date().toISOString();
27+
log.info("[PeriodicDbDeleter] Starting to collect deleted rows.", {
28+
periodicDeleterTickId: tickID,
29+
});
2630
const sortedTables = this.tableProvider.getSortedTables();
2731
const toBeDeleted: { table: string; deletions: string[] }[] = [];
2832
for (const table of sortedTables) {
29-
toBeDeleted.push(await this.collectRowsToBeDeleted(table));
33+
const rowsForTableToDelete = await this.collectRowsToBeDeleted(table);
34+
log.info(
35+
`[PeriodicDbDeleter] Identified ${rowsForTableToDelete.deletions.length} entries in ${rowsForTableToDelete.table} to be deleted.`,
36+
{
37+
periodicDeleterTickId: tickID,
38+
},
39+
);
40+
toBeDeleted.push(rowsForTableToDelete);
3041
}
3142
// when collecting the deletions do so in the inverse order as during update (delete dependency targes first)
3243
const pendingDeletions: Promise<void>[] = [];
3344
for (const { deletions } of toBeDeleted.reverse()) {
3445
for (const deletion of deletions) {
3546
pendingDeletions.push(
36-
this.query(deletion).catch((err) => log.error(`[PeriodicDbDeleter] sync error`, err)),
47+
this.query(deletion).catch((err) =>
48+
log.error(
49+
`[PeriodicDbDeleter] sync error`,
50+
{
51+
periodicDeleterTickId: tickID,
52+
query: deletion,
53+
},
54+
err,
55+
),
56+
),
3757
);
3858
}
3959
}
4060
await Promise.all(pendingDeletions);
61+
log.info("[PeriodicDbDeleter] Finished deleting records.", {
62+
periodicDeleterTickId: tickID,
63+
});
4164
};
4265
repeat(doSync, 30000); // deletion is never time-critical, so we should ensure we do not spam ourselves
4366
}

0 commit comments

Comments
 (0)