# File lib/smart_proxy_omaha/http_download.rb, line 11 def initialize(src, dst) @src = src @dst = dst end
# File lib/smart_proxy_omaha/http_download.rb, line 33 def join @task.join end
# File lib/smart_proxy_omaha/http_download.rb, line 24 def run with_filelock do logger.info "Downloading #{src} to #{dst}." res = download logger.info "Finished downloading #{dst}." res end end
# File lib/smart_proxy_omaha/http_download.rb, line 16 def start @task = Thread.new do @result = run end @task.abort_on_exception = true @task end
# File lib/smart_proxy_omaha/http_download.rb, line 39 def download http, request = connection_factory(src) http.request(request) do |response| open(dst, 'w') do |io| response.read_body do |chunk| io.write chunk end end end true end
# File lib/smart_proxy_omaha/http_download.rb, line 52 def with_filelock lock = Proxy::FileLock.try_locking(dst) if lock.nil? false else begin yield ensure Proxy::FileLock.unlock(lock) end end end