-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add queue to delete site builds older than 180 days #4352
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0206eca
chore: Make Build a paranoid model (enable soft deletion) #4336
svenaas 0a76a92
chore: Add queue to delete site builds older than 180 days #4336
svenaas 1dd8351
chore: Run build log archive job in dev and staging as well #4336
svenaas 7d4ec9e
Testing.
svenaas 30d3ed5
Switch to newer queue worker instantiation syntax.
svenaas 1aa3c58
More tests. Because it isn't working. WHY ISN'T IT WORKING?
svenaas 440ec49
chore: Add Queues section to OPERATIONS.md, starting with delete-olde…
svenaas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,6 +329,7 @@ module.exports = (sequelize, DataTypes) => { | |
afterCreate, | ||
afterUpdate, | ||
}, | ||
paranoid: true, | ||
} | ||
); | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { Queue } = require('bullmq'); | ||
|
||
const DeleteOlderBuildsQueueName = 'delete-older-builds'; | ||
|
||
class DeleteOlderBuildsQueue extends Queue { | ||
constructor(connection) { | ||
super(DeleteOlderBuildsQueueName, { connection }); | ||
} | ||
} | ||
|
||
module.exports = { | ||
DeleteOlderBuildsQueue, | ||
DeleteOlderBuildsQueueName, | ||
}; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const moment = require('moment'); | ||
const { Op } = require('sequelize'); | ||
const { Build } = require('../../models'); | ||
const Mailer = require('../../services/mailer'); | ||
const Slacker = require('../../services/slacker'); | ||
const { createJobLogger } = require('./utils'); | ||
|
||
async function deleteOlderBuilds(job) { | ||
const logger = createJobLogger(job); | ||
const cutoffDate = moment().subtract(180, 'days').startOf('day'); | ||
|
||
logger.log(`Deleting all builds completed before ${cutoffDate}.`); | ||
|
||
try { | ||
const numDeleted = await Build.destroy({ | ||
where: { | ||
completedAt: { | ||
[Op.lt]: cutoffDate.toDate(), | ||
}, | ||
}, | ||
}); | ||
logger.log(`Deleted ${numDeleted} builds.`); | ||
await logger.flush(); | ||
return 'OK'; | ||
} catch (error) { | ||
const errMsg = `Delete builds before ${cutoffDate.format('YYYY-MM-DD')} completed with error`; | ||
logger.log(errMsg, error); | ||
await logger.flush(); | ||
Mailer.init(); | ||
Slacker.init(); | ||
Mailer.sendAlert(errMsg, error); | ||
Slacker.sendAlert(errMsg, error); | ||
throw new Error(errMsg); | ||
} | ||
} | ||
|
||
module.exports = deleteOlderBuilds; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const TABLE = 'build'; | ||
|
||
exports.up = async db => { | ||
await db.addColumn(TABLE, 'deletedAt', { type: 'date', allowNull: true }); | ||
}; | ||
|
||
exports.down = async db => { | ||
db.removeColumn(TABLE, 'deletedAt'); | ||
}; |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we create the buckets for log archives in dev and staging and added the bucket service to the app manifest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only change I have made is this provisional code change. I didn't realize the buckets didn't exist, so that probably has to happen.
But FWIW the bucket service is already parameterized in
manifest.yml
asfederalist-((env))-s3-build-logs
. Would that not allow for the presence of these dev and staging buckets?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like non of the archive build log jobs were successful in dev so I was flagging as a possible culprit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked dev and build logs aren't archiving nightly and builds over 180 days aren't deleting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. It also looks like the migration on this PR hasn't run: