UNPKG

@azure-utils/storybooks

Version:

Utils to upload and manage Storybooks via Azure Functions and storage.

23 lines (21 loc) 1.16 kB
import { DEFAULT_PURGE_AFTER_DAYS, ONE_DAY_IN_MS } from "./constants-CsV1N9r4.mjs"; import { ProjectModel } from "./projects-DDVy3_77.mjs"; //#region src/handlers/timer-purge-handler.ts function timerPurgeHandler(connectionString) { return async (timer, context) => { context.log("Timer triggered to purge old builds...", JSON.stringify(timer)); const projectModel = new ProjectModel(context, connectionString); const projects = await projectModel.list(); for (const project of projects) { const { id, purgeBuildsAfterDays = DEFAULT_PURGE_AFTER_DAYS } = project; const expiryTime = new Date(Date.now() - purgeBuildsAfterDays * ONE_DAY_IN_MS); context.log(`[${id}] Timer - Purge builds which were last modified more than ${purgeBuildsAfterDays} days ago - since ${new Date(expiryTime)}`); const buildModel = projectModel.buildModel(project.id); const expiredBuilds = await buildModel.list({ filter: `Timestamp lt '${expiryTime.toISOString()}'` }); for (const build of expiredBuilds) await buildModel.delete(build.sha); } }; } //#endregion export { timerPurgeHandler }; //# sourceMappingURL=timer-purge-handler-DSRkR3S8.mjs.map