-
Notifications
You must be signed in to change notification settings - Fork 8
Add purger script for removing stale jobs #55
Conversation
contrib/build_purger.rb
Outdated
# jobs that have a symlink either as a group or as latest won't be deleted | ||
groups_and_latest = [] | ||
group_jobs = Dir["#{groups_path}/*"] | ||
groups_and_latest << `readlink #{Dir["latest_path"]}` |
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.
You can use File.readlink()
and avoid the shell escape.
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.
good catch, fixed
contrib/build_purger.rb
Outdated
groups_and_latest << `readlink #{j}`.strip | ||
end | ||
|
||
ready_path = File.join(data_path, "/ready") |
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.
nit, you should drop the slash. File.join
is used to avoid hardcoding the file seperator (/
) for portability (e.g. on windows systems)
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.
done
We have jobs that don't have a buildinfo file,right? We should have a plan for them. |
Generally, the file join logic is not consistent throughout the script, you both use |
contrib/build_purger.rb
Outdated
options = {} | ||
OptionParser.new do |opts| | ||
opts.banner = "Usage: build_purger.rb [options]" | ||
opts.on('--days DAYS', 'Stale point') { |v| options[:stale_point] = Time.now - v.to_i*24*60*60 } |
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.
Use the more aggressive Integer(v)
.
Also, can we use something more descriptive than "Stale point"? For example --older-than
would've been better imo:
--older-than DAYS - remove builds older than
DAYS
days
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.
done
contrib/build_purger.rb
Outdated
puts "would delete jobs: #{stale_jobs}" | ||
else | ||
stale_jobs.each do |sj| | ||
`btrfs subvolume delete #{sj}` |
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.
btrfs subvolume delete
also accepts multiple arguments, so you can do this in a single command.
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.
Great catch, thank you for pointing this out! The code has been fixed to play with multiple arguments.
contrib/build_purger.rb
Outdated
@@ -0,0 +1,49 @@ | |||
#!/usr/bin/env ruby |
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.
You can drop the .rb
extension since this you added the shebang. Also a suggestion for a more idiomatic name mistry-purge-builds
.
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.
dropped the extension and renamed
contrib/build_purger.rb
Outdated
require 'json' | ||
require 'time' | ||
require 'optparse' | ||
require 'yaml' |
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.
Is this actually needed?
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.
nope, removed. I added it as part of the experimentation with a static yaml file for the commands but it was overkill.
contrib/build_purger.rb
Outdated
|
||
options = {} | ||
OptionParser.new do |opts| | ||
opts.banner = "Usage: build_purger.rb [options]" |
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.
We could add a small description here so that the user knows what this is about. Something like:
Purge old mistry builds from the file system.
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.
done
Jobs that don't have the buildinfo file will be considered stale and eventually will be deleted, except those that are the symbolic link target of |
Not sure about that, I think it's better to delete them (we should make sure that it doesn't affect the server readlink logic). The problem is that this way we will never delete obsolete groups and reclaim their space. |
Please describe in the commit message (and PR) why this change is needed (ie. that it's a best-effort, temporary solution to #25) and that it will be replaced later when we implement a solution built-in to mistryd. |
Sounds good. As far as the server readlink logic is concerned, we will be dropping the symbolic links if their target job directory has been removed. |
303f566
to
45eb939
Compare
Comments addressed and updated PR description. |
45eb939
to
8970581
Compare
contrib/mistry-purge-builds
Outdated
if options[:dry_run] | ||
puts "would delete jobs: #{stale_jobs}" | ||
else | ||
`btrfs subvolume delete #{stale_jobs.join(' ')}` |
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.
What will happen if there are no stale jobs?
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.
Unless I'm very much mistaken, the command will print an error. Added a simple condition to mitigate this.
contrib/mistry-purge-builds
Outdated
|
||
options = {} | ||
OptionParser.new do |opts| | ||
opts.banner = "Purge old mistry builds from the file system.\nUsage: mistry-purge-builds [options]" |
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.
You can use $0
for the current file name.
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, thanks 👍
A best-effort, temporary solution to #25. The script will be replaced later when we implement a solution built-in to mistryd.
d0fb94d
to
ca903e5
Compare
A best-effort, temporary solution to #25.
The script will be replaced later when we implement a solution built-in to mistryd.