class Proxy::Omaha::HttpDownload
Attributes
dst[RW]
result[RW]
src[RW]
Public Class Methods
new(src, dst)
click to toggle source
# File lib/smart_proxy_omaha/http_download.rb, line 11 def initialize(src, dst) @src = src @dst = dst end
Public Instance Methods
join()
click to toggle source
# File lib/smart_proxy_omaha/http_download.rb, line 33 def join @task.join end
run()
click to toggle source
# 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
start()
click to toggle source
# 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
Private Instance Methods
download()
click to toggle source
# 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
with_filelock() { || ... }
click to toggle source
# 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