Class: Turbotlib::FTPDelegator

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/turbotlib/ftp.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object

echanges.dila.gouv.fr sometimes returns a local IP (192.168.30.9) for the host in #makepasv. We can store the first host received (which we assume to be good), and return it every time. However, even with a good IP, the next command times out. So, we instead retry the entire command with a new client, after closing the old client.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/turbotlib/ftp.rb', line 14

def method_missing(m, *args, &block)
  on_retry = Proc.new do |exception, try, elapsed_time, next_interval|
    @delegate_sd_obj.error("#{exception.message} on #{@delegate_sd_obj.last_cmd}")
    @delegate_sd_obj.close

    ftp = FTP.new(*@delegate_sd_obj.initialize_args)
    ftp.logger = @delegate_sd_obj.logger
    ftp.root_path = @delegate_sd_obj.root_path
    ftp.passive = true

    ftp.
    dir = @delegate_sd_obj.last_dir.to_s
    unless dir.empty?
      ftp.chdir(dir)
    end

    __setobj__(ftp)
  end

  exception_classes = [Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::ETIMEDOUT, EOFError]
  if Net.const_defined?(:ReadTimeout) # Ruby 2
    exception_classes << Net::ReadTimeout
  end

  Retriable.retriable(on: exception_classes, on_retry: on_retry) do
    super
  end
end