Skip to content

Commit 6261551

Browse files
authored
Merge pull request #20285 from Homebrew/download_queue_tweaks
Improve Download Queue behaviour
2 parents 0f92fd7 + e5d940f commit 6261551

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

Library/Homebrew/api/cask.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,18 @@ def self.cached_json_file_path
5555
end
5656

5757
sig {
58-
params(download_queue: T.nilable(::Homebrew::DownloadQueue))
58+
params(download_queue: T.nilable(::Homebrew::DownloadQueue), stale_seconds: Integer)
5959
.returns([T.any(T::Array[T.untyped], T::Hash[String, T.untyped]), T::Boolean])
6060
}
61-
def self.fetch_api!(download_queue: nil)
62-
Homebrew::API.fetch_json_api_file api_filename, download_queue:
61+
def self.fetch_api!(download_queue: nil, stale_seconds: Homebrew::EnvConfig.api_auto_update_secs.to_i)
62+
Homebrew::API.fetch_json_api_file api_filename, stale_seconds:, download_queue:
6363
end
6464

6565
sig {
66-
params(download_queue: T.nilable(::Homebrew::DownloadQueue))
66+
params(download_queue: T.nilable(::Homebrew::DownloadQueue), stale_seconds: Integer)
6767
.returns([T.any(T::Array[T.untyped], T::Hash[String, T.untyped]), T::Boolean])
6868
}
69-
def self.fetch_tap_migrations!(download_queue: nil)
70-
stale_seconds = Homebrew::API::TAP_MIGRATIONS_STALE_SECONDS
69+
def self.fetch_tap_migrations!(download_queue: nil, stale_seconds: Homebrew::API::TAP_MIGRATIONS_STALE_SECONDS)
7170
Homebrew::API.fetch_json_api_file "cask_tap_migrations.jws.json", stale_seconds:, download_queue:
7271
end
7372

Library/Homebrew/api/formula.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,18 @@ def self.cached_json_file_path
5555
end
5656

5757
sig {
58-
params(download_queue: T.nilable(Homebrew::DownloadQueue))
58+
params(download_queue: T.nilable(Homebrew::DownloadQueue), stale_seconds: Integer)
5959
.returns([T.any(T::Array[T.untyped], T::Hash[String, T.untyped]), T::Boolean])
6060
}
61-
def self.fetch_api!(download_queue: nil)
62-
Homebrew::API.fetch_json_api_file api_filename, download_queue:
61+
def self.fetch_api!(download_queue: nil, stale_seconds: Homebrew::EnvConfig.api_auto_update_secs.to_i)
62+
Homebrew::API.fetch_json_api_file api_filename, stale_seconds:, download_queue:
6363
end
6464

6565
sig {
66-
params(download_queue: T.nilable(Homebrew::DownloadQueue))
66+
params(download_queue: T.nilable(Homebrew::DownloadQueue), stale_seconds: Integer)
6767
.returns([T.any(T::Array[T.untyped], T::Hash[String, T.untyped]), T::Boolean])
6868
}
69-
def self.fetch_tap_migrations!(download_queue: nil)
70-
stale_seconds = Homebrew::API::TAP_MIGRATIONS_STALE_SECONDS
69+
def self.fetch_tap_migrations!(download_queue: nil, stale_seconds: Homebrew::API::TAP_MIGRATIONS_STALE_SECONDS)
7170
Homebrew::API.fetch_json_api_file "formula_tap_migrations.jws.json", stale_seconds:, download_queue:
7271
end
7372

Library/Homebrew/brew.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,17 @@
8888
cmd_class = Homebrew::AbstractCommand.command(cmd)
8989
Homebrew.running_command = cmd
9090
if cmd_class
91-
if Homebrew::EnvConfig.download_concurrency > 1
91+
if !Homebrew::EnvConfig.no_install_from_api? && Homebrew::EnvConfig.download_concurrency > 1
9292
require "download_queue"
9393
require "api"
9494
require "api/formula"
9595
require "api/cask"
9696
download_queue = Homebrew::DownloadQueue.new
97-
Homebrew::API::Formula.fetch_api!(download_queue:)
98-
Homebrew::API::Formula.fetch_tap_migrations!(download_queue:)
99-
Homebrew::API::Cask.fetch_api!(download_queue:)
100-
Homebrew::API::Cask.fetch_tap_migrations!(download_queue:)
97+
stale_seconds = 86400 # 1 day
98+
Homebrew::API::Formula.fetch_api!(download_queue:, stale_seconds:)
99+
Homebrew::API::Formula.fetch_tap_migrations!(download_queue:, stale_seconds:)
100+
Homebrew::API::Cask.fetch_api!(download_queue:, stale_seconds:)
101+
Homebrew::API::Cask.fetch_tap_migrations!(download_queue:, stale_seconds:)
101102
begin
102103
download_queue.fetch
103104
ensure

Library/Homebrew/cmd/fetch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def run
184184

185185
sig { returns(Integer) }
186186
def retries
187-
@retries ||= T.let(args.retry? ? FETCH_MAX_TRIES : 0, T.nilable(Integer))
187+
@retries ||= T.let(args.retry? ? FETCH_MAX_TRIES : 1, T.nilable(Integer))
188188
end
189189

190190
sig { returns(DownloadQueue) }

Library/Homebrew/download_queue.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
module Homebrew
1010
class DownloadQueue
1111
sig { params(retries: Integer, force: T::Boolean, pour: T::Boolean).void }
12-
def initialize(retries: 0, force: false, pour: false)
12+
def initialize(retries: 1, force: false, pour: false)
1313
@concurrency = T.let(EnvConfig.download_concurrency, Integer)
1414
@quiet = T.let(@concurrency > 1, T::Boolean)
1515
@tries = T.let(retries + 1, Integer)

0 commit comments

Comments
 (0)