Created
July 28, 2021 07:18
-
-
Save 402332509/1eae3f21a0cba33813d04b50ab46f161 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
login, | |
queryGenerator, | |
deleleSobject, | |
query, | |
executeAnonymous, | |
} from "@common/promisify-js-force"; | |
import { chunk } from "lodash"; | |
export const main_handler = async (event, context, callback) => { | |
await login(); | |
const sumResult = await query(`select sum(LogLength) totalLength from ApexLog`); | |
let total = sumResult.records[0].totalLength; | |
const threshold = 700 * 1024 * 1024; | |
console.log(total); | |
if (total < threshold) { | |
return; | |
} | |
for await (const { records } of queryGenerator(` select Id, LogLength from ApexLog `)) { | |
for (const logChunk of chunk(records, 50)) { | |
await deleleSobject( | |
"ApexLog", | |
logChunk.map((log) => log.Id) | |
); | |
total -= logChunk.reduce((acc, log) => acc + log.LogLength, 0); | |
console.log(total); | |
} | |
if (total < threshold) { | |
break; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment