Skip to content

Instantly share code, notes, and snippets.

@mccun934
Last active June 28, 2019 15:28
Show Gist options
  • Save mccun934/dfe1bda1315816c89666ad2ebf9c9d0c to your computer and use it in GitHub Desktop.
Save mccun934/dfe1bda1315816c89666ad2ebf9c9d0c to your computer and use it in GitHub Desktop.
namespace :taskbench do
desc <<-END_DESC
Loads up some tasks
END_DESC
def parallelize(param_lists, max_number_of_forks = 20)
page = 0
page_size = max_number_of_forks
loop do
page += 1
items = param_lists.paginate(:page => page, :per_page => page_size)
break if items.empty?
fork do
items.each do |item|
yield item
end
end
end
end
def fetch_hosts(count)
count = ENV['count'] || 10
hosts = ::Host::Managed.unscoped.order('RANDOM()').limit(count)
end
task :hostupdate => :environment do
puts 'Starting task load..'
parallelize(fetch_hosts) do |host|
begin
User.current = User.anonymous_admin
facts = host.facts
task = ForemanTasks.async_task(::Actions::Katello::Host::Update,host, facts)
puts "task: #{y} created"
rescue
puts "Exception launching task."
end
end
puts "Finished"
end
task :genapp => :environment do
puts 'Starting task load..'
puts 'GenerateApplicability..'
parallelize(fetch_hosts) do |host|
begin
User.current = User.anonymous_admin
task = ForemanTasks.async_task(::Actions::Katello::Host::GenerateApplicability, [host])
puts "task: #{y} created"
rescue
puts "Exception launching task."
end
end
puts "Finished"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment