Skip to content

feat(server): Server should periodically delete old builds#471

Merged
patrickhulce merged 2 commits into
GoogleChrome:masterfrom
koh110:delete_old
Oct 18, 2020
Merged

feat(server): Server should periodically delete old builds#471
patrickhulce merged 2 commits into
GoogleChrome:masterfrom
koh110:delete_old

Conversation

@koh110
Copy link
Copy Markdown
Contributor

@koh110 koh110 commented Oct 15, 2020

I add cron task that delete old builds on sql to the server.

fixes: #463

Copy link
Copy Markdown
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findBuildsBeforeTimestamp maybe?

throw new Error('Invalid range');
}

const runAt = new Date(now.setDate(now.getDate() + range));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about...

Suggested change
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of dateRange what do you think about maxAgeInDays

Comment thread types/server.d.ts Outdated
sqlConnectionUrl?: string;
sqlDangerouslyResetDatabase?: boolean;
sequelizeOptions?: import('sequelize').Options;
deleteOldBuilds?: {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread types/collect.d.ts

export interface Options {
url?: string | string[];
autodiscoverUrlBlocklist?: string | string[];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this please :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my mistake! I overlooked that. Thanks.

@@ -0,0 +1,21 @@
'use strict';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add license comment

Comment thread packages/server/test/cron/delete-old-builds.test.js
Comment thread packages/server/src/cron/utils.js
Comment thread packages/server/src/server.js Outdated
app.use(errorMiddleware);

startPsiCollectCron(storageMethod, options);
startDeletingOldBuildsCron(storageMethod, options);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for consistency with option proposed name startDeleteOldBuildsCron?

Comment thread packages/server/src/cron/delete-old-builds.js
Copy link
Copy Markdown
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thank you @koh110! 🎉

@patrickhulce patrickhulce merged commit c324f3f into GoogleChrome:master Oct 18, 2020
@koh110
Copy link
Copy Markdown
Contributor Author

koh110 commented Oct 19, 2020

@patrickhulce Thank you for your review & merge!
I can't wait to use this feature in my lighthouse-ci! Is there anything I can do to help with the release?

@patrickhulce
Copy link
Copy Markdown
Collaborator

Nothing in particular, I'll try to ship it out this week 👍

@koh110
Copy link
Copy Markdown
Contributor Author

koh110 commented Oct 19, 2020

I appreciate you! 👍

denkrasnov pushed a commit to Travix-International/lighthouse-ci that referenced this pull request Oct 29, 2020
@emmekappa
Copy link
Copy Markdown

@patrickhulce any idea when this will be released? Is it planned for the 0.6.2?

@patrickhulce
Copy link
Copy Markdown
Collaborator

@emmekappa this has been available since v0.5.1

@emmekappa
Copy link
Copy Markdown

@patrickhulce is somehow possible to configure the numbers of days? I cannot see anything in the doc

@patrickhulce
Copy link
Copy Markdown
Collaborator

@emmekappa yes it is, it accepts two options. maxAgeInDays is what you're looking for

It wasn't added to the docs yet, but PR welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server should periodically delete old builds

3 participants