Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Add purger script for removing stale jobs #55

Merged
merged 1 commit into from
Apr 25, 2018
Merged

Conversation

apostergiou
Copy link
Contributor

@apostergiou apostergiou commented Apr 24, 2018

A best-effort, temporary solution to #25.

The script will be replaced later when we implement a solution built-in to mistryd.

@apostergiou apostergiou added this to the 1.0 milestone Apr 24, 2018
@apostergiou apostergiou self-assigned this Apr 24, 2018
# 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"]}`
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, fixed

groups_and_latest << `readlink #{j}`.strip
end

ready_path = File.join(data_path, "/ready")
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ctrochalakis
Copy link
Member

We have jobs that don't have a buildinfo file,right? We should have a plan for them.

@ctrochalakis
Copy link
Member

Generally, the file join logic is not consistent throughout the script, you both use File.join and string concatenation with a /.

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 }
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

puts "would delete jobs: #{stale_jobs}"
else
stale_jobs.each do |sj|
`btrfs subvolume delete #{sj}`
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -0,0 +1,49 @@
#!/usr/bin/env ruby
Copy link
Contributor

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.

Copy link
Contributor Author

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

require 'json'
require 'time'
require 'optparse'
require 'yaml'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this actually needed?

Copy link
Contributor Author

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.


options = {}
OptionParser.new do |opts|
opts.banner = "Usage: build_purger.rb [options]"
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@apostergiou
Copy link
Contributor Author

We have jobs that don't have a buildinfo file,right? We should have a plan for them.

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 groups and latest.

@skroutz skroutz deleted a comment from agis Apr 24, 2018
@ctrochalakis
Copy link
Member

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 groups and latest.

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.

@agis
Copy link
Contributor

agis commented Apr 24, 2018

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.

@apostergiou
Copy link
Contributor Author

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.

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.

@apostergiou
Copy link
Contributor Author

Comments addressed and updated PR description.

if options[:dry_run]
puts "would delete jobs: #{stale_jobs}"
else
`btrfs subvolume delete #{stale_jobs.join(' ')}`
Copy link
Contributor

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?

Copy link
Contributor Author

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.


options = {}
OptionParser.new do |opts|
opts.banner = "Purge old mistry builds from the file system.\nUsage: mistry-purge-builds [options]"
Copy link
Contributor

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.

Copy link
Contributor Author

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.
@apostergiou apostergiou merged commit b528fa0 into master Apr 25, 2018
@apostergiou apostergiou deleted the build-purger branch April 25, 2018 09:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants