class Beanstalkify::Environment
Constants
- HEALTHY_TIMEOUT
- POLL_INTERVAL
- STATUS_CHANGE_TIMEOUT
Attributes
name[RW]
Public Class Methods
new(archive, name)
click to toggle source
# File lib/beanstalkify/environment.rb, line 11 def initialize(archive, name) @name = [archive.app_name, name].join("-") @beanstalk = Beanstalk.api end
Public Instance Methods
create!(archive, stack, cnames, settings=[])
click to toggle source
Assuming the archive has already been uploaded, create a new environment with the app deployed onto the provided stack. Attempts to use the first available cname in the cnames array.
# File lib/beanstalkify/environment.rb, line 30 def create!(archive, stack, cnames, settings=[]) params = { application_name: archive.app_name, version_label: archive.version, environment_name: self.name, solution_stack_name: stack, option_settings: settings } cnames.each do |c| if dns_available(c) params[:cname_prefix] = c break else puts "CNAME #{c} is unavailable." end end @beanstalk.create_environment(params) end
deploy!(app, settings=[])
click to toggle source
Assuming the provided app has already been uploaded, update this environment to the app’s version Optionally pass in a bunch of settings to override
# File lib/beanstalkify/environment.rb, line 19 def deploy!(app, settings=[]) @beanstalk.update_environment({ version_label: app.version, environment_name: self.name, option_settings: settings }) end
dns_available(cname)
click to toggle source
# File lib/beanstalkify/environment.rb, line 49 def dns_available(cname) @beanstalk.check_dns_availability({ cname_prefix: cname })[:available] end
healthy?()
click to toggle source
# File lib/beanstalkify/environment.rb, line 60 def healthy? e = describe_environment e ? e[:health] == 'Green' : false end
status()
click to toggle source
# File lib/beanstalkify/environment.rb, line 65 def status e = describe_environment e ? e[:status] : "" end
url()
click to toggle source
# File lib/beanstalkify/environment.rb, line 55 def url e = describe_environment e ? e[:cname] : "" end
wait_until_healthy()
click to toggle source
# File lib/beanstalkify/environment.rb, line 75 def wait_until_healthy puts "Waiting until #{self.name} is healthy..." wait_until -> { healthy? }, HEALTHY_TIMEOUT end
wait_until_status_is_not(old_status)
click to toggle source
# File lib/beanstalkify/environment.rb, line 70 def wait_until_status_is_not(old_status) puts "Waiting for #{self.name} to finish #{old_status.downcase}..." wait_until -> { status != old_status }, STATUS_CHANGE_TIMEOUT end
Private Instance Methods
describe_environment()
click to toggle source
# File lib/beanstalkify/environment.rb, line 82 def describe_environment @beanstalk.describe_environments({ environment_names: [name], include_deleted: false }).data[:environments].first end
wait_until(condition, timeout)
click to toggle source
# File lib/beanstalkify/environment.rb, line 89 def wait_until(condition, timeout) until condition.call or timeout <= 0 print '.' sleep POLL_INTERVAL timeout -= POLL_INTERVAL end puts end