run cleanup every three hours

This commit is contained in:
Asier Isayas
2026-01-06 13:24:56 -05:00
parent 38b7de4f66
commit a34c485ae5
3 changed files with 25 additions and 45 deletions

View File

@@ -90,10 +90,14 @@ async function deleteWithRetry(client, database, accountName) {
while (attempt < maxRetries) {
try {
await client.sqlResources.deleteSqlDatabase(resourceGroupName, accountName, database.name);
const timestamp = Number(database.resource._ts) * 1000;
console.log(`DELETED: ${accountName} | ${database.name} | Age: ${friendlyTime(Date.now() - timestamp)}`);
return; // Successfully deleted, exit the function
if (timestamp && timestamp < thirtyMinutesAgo) {
await client.sqlResources.deleteSqlDatabase(resourceGroupName, accountName, database.name);
console.log(`DELETED: ${accountName} | ${database.name} | Age: ${friendlyTime(Date.now() - timestamp)}`);
} else {
console.log(`SKIPPED: ${accountName} | ${database.name} | Age: ${friendlyTime(Date.now() - timestamp)}`);
}
return;
} catch (error) {
if (error.statusCode === 429) {
// Throttling error (HTTP 429), apply exponential backoff