Class: Dploy::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/dploy/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(server, project, environment, version) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
# File 'lib/dploy/client.rb', line 8

def initialize(server, project, environment, version)
  @server = server
  @project = project
  @environment = environment
  @version = version
end

Instance Method Details

#deployObject



15
16
17
18
# File 'lib/dploy/client.rb', line 15

def deploy
  deploy_data = JSON.parse((RestClient.post "http://#{@server}/deploy", { :project => @project, :environment => @environment, :version => @version }.to_json, :content_type => :json, :accept => :json))
  monitor_deploy(deploy_data['id'])
end

#monitor_deploy(deploy_id) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dploy/client.rb', line 20

def monitor_deploy(deploy_id)
  failed = false
  finished = false
  last_id = "000000000000000000000000"
  
  while not finished
    logs = JSON.parse(RestClient.get( "http://#{@server}/logs/#{deploy_id}/?start_id=#{last_id}", :accept => :json), :symbolize_names => true)
    logs.each do |row|
      puts "#{row[:log_type]}: #{row[:message]}"
      STDOUT.flush
      last_id = row[:_id]
      if row[:log_type] == "completion"
        finished = true 
        if row[:status] == "failure"
          failed = true
        end
      end    
    end
    sleep 1
  end
  exit 1 if failed
end