Class: Minke::Helpers::Helper
- Inherits:
-
Object
- Object
- Minke::Helpers::Helper
- Defined in:
- lib/minke/helpers/helper.rb
Instance Method Summary collapse
-
#copy_assets(from, to) ⇒ Object
copy assets from one location to another.
- #execute_shell_command(command) ⇒ Object
- #fatal_error(message) ⇒ Object
-
#invoke_task(task) ⇒ Object
invoke a rake task.
- #load_consul_data(server, config_file) ⇒ Object
-
#wait_for_HTTPOK(url, count, successes = 3) ⇒ Object
waits until a 200 response is received from the given url.
Instance Method Details
#copy_assets(from, to) ⇒ Object
copy assets from one location to another
6 7 8 9 10 11 12 13 14 |
# File 'lib/minke/helpers/helper.rb', line 6 def copy_assets from, to directory = to if File.directory?(to) directory = File.dirname(to) end Dir.mkdir directory unless Dir.exist? to FileUtils.cp_r from, to end |
#execute_shell_command(command) ⇒ Object
29 30 31 32 |
# File 'lib/minke/helpers/helper.rb', line 29 def execute_shell_command command puts `#{command}` $?.exitstatus end |
#fatal_error(message) ⇒ Object
34 35 36 |
# File 'lib/minke/helpers/helper.rb', line 34 def fatal_error abort end |
#invoke_task(task) ⇒ Object
invoke a rake task
18 19 20 |
# File 'lib/minke/helpers/helper.rb', line 18 def invoke_task task Rake::Task[task].invoke end |
#load_consul_data(server, config_file) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/minke/helpers/helper.rb', line 22 def load_consul_data server, config_file wait_for_HTTPOK "#{server}/v1/status/leader", 0, 1 loader = ConsulLoader::Loader.new(ConsulLoader::ConfigParser.new) puts config_file loader.load_config config_file, server end |
#wait_for_HTTPOK(url, count, successes = 3) ⇒ Object
waits until a 200 response is received from the given url
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/minke/helpers/helper.rb', line 40 def wait_for_HTTPOK url, count, successes = 3 begin response = RestClient.send("get", url) rescue end if response == nil || !response.code.to_i == 200 puts "Waiting for server #{url} to start" sleep 1 if count < 180 wait_for_HTTPOK url, count + 1 else raise 'Server failed to start' end else if successes > 0 puts "Server: #{url} passed health check, #{successes} checks to go..." sleep 1 wait_for_HTTPOK url, count + 1, successes - 1 else puts "Server: #{url} healthy" end end end |