Skip to content

Commit 3ab54f1

Browse files
committed
my_sleep()
1 parent db10011 commit 3ab54f1

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/VersionsJSONUtil.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,17 @@ Base.@kwdef struct HeadInfo
359359
last_modified::Union{String, Nothing}
360360
end
361361

362+
# We call this function before hitting an upstream server.
363+
# By default, it is a sleep(0), but we can make this user-configurable.
364+
# So that way, if a user is using a mirror that has rate-limits, they can configure this
365+
# to help them stay under the limits.
366+
function my_sleep()
367+
sleep(0)
368+
return nothing
369+
end
370+
362371
function get_new_headinfo_for_url(url::URI)
372+
my_sleep()
363373
response = HTTP.head(url; status_exception = false)
364374
status = response.status
365375
if status != 200
@@ -428,10 +438,16 @@ function get_tags()
428438
@info("Probing for tag list...")
429439
request_path = "repos/JuliaLang/julia/git/refs/tags"
430440
token = strip(get(ENV, "GITHUB_TOKEN", ""))
441+
442+
443+
431444
if !isempty(token)
432445
# The user provided GITHUB_TOKEN, so we use that to authenticate to GitHub API.
433446
# We don't cache this result - this ensures we get the freshest data.
434447
auth = GitHub.authenticate(token)
448+
449+
# Note: GitHub.jl now has rate-limit support built-in.
450+
# So we don't call my_sleep() here.
435451
return GitHub.gh_get_json(GitHub.DEFAULT_API, "/$request_path"; auth)
436452
else
437453
# The user didn't provide GITHUB_TOKEN, so we have to make an unauthenticated call
@@ -549,6 +565,7 @@ function main!(content::OutputJsonContent, cfg::Config)
549565
number_urls_tried += 1
550566

551567
# This will download the file to a tempfile
568+
my_sleep()
552569
filepath = Downloads.download(string(url))
553570

554571
if filesize(filepath) == 0
@@ -643,6 +660,7 @@ function main!(content::OutputJsonContent, cfg::Config)
643660
asc_filename = basename(string(asc_url))
644661
@debug "Downloading $asc_filename"
645662
try
663+
my_sleep()
646664
asc_filepath = Downloads.download(string(asc_url))
647665
asc_signature = String(read(asc_filepath))
648666
rm(asc_filepath)

src/web_cache_utilities.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using Dates: Dates, now, UTC, unix2datetime, TimePeriod, Hour
22
using URIs: URI
33

44
function download_to_cache(filename::String, url::Union{String, URI})
5+
my_sleep()
56
file_path = _hit_file_cache(filename) do file_path
67
r = open(io -> HTTP.get(url; response_stream=io), file_path, "w")
78
if r.status != 200

0 commit comments

Comments
 (0)