Skip to content

Instantly share code, notes, and snippets.

@tobert
Last active January 14, 2022 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobert/435a5ba9fb07de242f273c80ab40ee56 to your computer and use it in GitHub Desktop.
Save tobert/435a5ba9fb07de242f273c80ab40ee56 to your computer and use it in GitHub Desktop.
def run_in_threads(*tasks)
if Rails.env.test? || Rails.env.integration_test?
tasks.each(&:call)
else
tasks.map do |task|
Thread.new {
ApplicationRecord.connection_pool.with_connection(&task)
}
end.each(&:join)
end
end
run_in_threads(
proc { turn_server_power_on },
proc { enable_switch_ports },
proc { set_server_boot_device }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment