Class: SwitchTower::Transfer

Inherits:
Object
  • Object
show all
Defined in:
lib/switchtower/transfer.rb

Overview

This class encapsulates a single file transfer to be performed in parallel across multiple machines, using the SFTP protocol.

Instance Method Summary collapse

Constructor Details

#initialize(servers, actor, filename, params = {}) ⇒ Transfer

:nodoc:



22
23
24
25
26
27
28
29
30
# File 'lib/switchtower/transfer.rb', line 22

def initialize(servers, actor, filename, params={}) #:nodoc:
  @servers = servers
  @actor = actor
  @filename = filename
  @params = params
  @completed = 0
  @failed = 0
  @sftps = setup_transfer
end

Instance Method Details

#loggerObject

:nodoc:



32
33
34
# File 'lib/switchtower/transfer.rb', line 32

def logger #:nodoc:
  @actor.logger
end

#process!Object

Uploads to all specified servers in parallel.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/switchtower/transfer.rb', line 37

def process!
  logger.debug "uploading #{@filename}"

  loop do
    @sftps.each { |sftp| sftp.channel.connection.process(true) }
    break if @completed == @servers.length
  end

  logger.trace "upload finished"

  if @failed > 0
    raise "upload of #{@filename} failed on one or more hosts"
  end

  self
end