feat(server): Server should periodically delete old builds#471
Conversation
patrickhulce
left a comment
There was a problem hiding this comment.
thank you @koh110 this is fantastic!! 🎉
those tests and refactor to share cron utils are great 💯
| * @param {Date} runAt | ||
| * @return {Promise<LHCI.ServerCommand.Build[]>} | ||
| */ | ||
| async findOldBuilds(runAt) { |
There was a problem hiding this comment.
findBuildsBeforeTimestamp maybe?
| throw new Error('Invalid range'); | ||
| } | ||
|
|
||
| const runAt = new Date(now.setDate(now.getDate() + range)); |
There was a problem hiding this comment.
WDYT about...
| const runAt = new Date(now.setDate(now.getDate() + range)); | |
| const DAY_IN_MS = 24 * 60 * 60 * 1000; | |
| const cutoffTime = new Date(Date.now() - maxAgeInDays * DAY_IN_MS)); |
or something like that? setDate is clever but I worry it relies on a bit too much knowledge of range needing to be negative in config, a bit harder to think through for correctness across month/year boundaries, etc
There was a problem hiding this comment.
I agree with your comment.
I worry it relies on a bit too much knowledge of range needing to be negative in config
Your code looks to be easier than my code to understand. Thanks for the good suggestions.
I will change it.
| return; | ||
| } | ||
|
|
||
| if (!options.storage.deleteOldBuilds.schedule || !options.storage.deleteOldBuilds.dateRange) { |
There was a problem hiding this comment.
instead of dateRange what do you think about maxAgeInDays
| sqlConnectionUrl?: string; | ||
| sqlDangerouslyResetDatabase?: boolean; | ||
| sequelizeOptions?: import('sequelize').Options; | ||
| deleteOldBuilds?: { |
There was a problem hiding this comment.
I'm not sure this belongs at the StorageOptions layer since the storage class doesn't know about or do anything with this cron at all.
can we move up to Options?
WDYT about deleteOldBuildsCron
There was a problem hiding this comment.
This function only works when the storage option is 'sql', so I put it in StorageOption.
But, I agree with your comment. I move up to Options.
|
|
||
| export interface Options { | ||
| url?: string | string[]; | ||
| autodiscoverUrlBlocklist?: string | string[]; |
There was a problem hiding this comment.
revert this please :)
There was a problem hiding this comment.
This is my mistake! I overlooked that. Thanks.
| @@ -0,0 +1,21 @@ | |||
| 'use strict'; | |||
| app.use(errorMiddleware); | ||
|
|
||
| startPsiCollectCron(storageMethod, options); | ||
| startDeletingOldBuildsCron(storageMethod, options); |
There was a problem hiding this comment.
for consistency with option proposed name startDeleteOldBuildsCron?
patrickhulce
left a comment
There was a problem hiding this comment.
LGTM thank you @koh110! 🎉
|
@patrickhulce Thank you for your review & merge! |
|
Nothing in particular, I'll try to ship it out this week 👍 |
|
I appreciate you! 👍 |
|
@patrickhulce any idea when this will be released? Is it planned for the |
|
@emmekappa this has been available since v0.5.1 |
|
@patrickhulce is somehow possible to configure the numbers of days? I cannot see anything in the doc |
|
@emmekappa yes it is, it accepts two options. It wasn't added to the docs yet, but PR welcome :) |
I add cron task that delete old builds on sql to the server.
fixes: #463