Class: Beni::Vendor::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/beni/vendor/downloader.rb

Overview

Tarball download with exponential-backoff retry on transient network failures. One instance per (url, dest) pair; reuse is not supported and not needed by Beni::Tasks.

Public contract is the single #download entry point; TRANSIENT_ERRORS and MAX_RETRIES are exposed as tunable knobs but the retry mechanics themselves are internal.

Constant Summary collapse

MAX_RETRIES =

Retry attempts wait 1 << attempt seconds (2 + 4 + 8 = 14s total) — enough to ride out a GitHub archive 502 / TCP read timeout.

3
TRANSIENT_ERRORS =

Transient network errors retried by the internal with_retry wrapper. OpenURI::HTTPError is narrowed to 5xx; 4xx (URL typo, deleted repo) bypasses the retry path.

[
  OpenURI::HTTPError, Net::ReadTimeout, Net::OpenTimeout,
  Errno::ECONNRESET, SocketError
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(url, dest) ⇒ Downloader

Returns a new instance of Downloader.



29
30
31
32
# File 'lib/beni/vendor/downloader.rb', line 29

def initialize(url, dest)
  @url = url
  @dest = dest
end

Instance Method Details

#downloadObject

Fetch url into dest atomically via a .part sidecar, retrying transient failures with exponential backoff. Permanent failures (4xx, DNS resolution failure on non-network condition) surface immediately. Raises whatever the underlying URI#open raises after the retry budget is exhausted.



39
40
41
42
43
44
# File 'lib/beni/vendor/downloader.rb', line 39

def download
  FileUtils.mkdir_p(File.dirname(@dest))
  tmp = "#{@dest}.part"
  with_retry { fetch(tmp) }
  File.rename(tmp, @dest)
end