Skip to content

Commit

Permalink
Flush logging during downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
natgeo-wong committed Sep 24, 2023
1 parent 6287e00 commit e880ac2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/downloads/cdsapi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ function retrieve(
resp_dict = JSON.parse(String(response.body))
data = Dict("state" => "queued")

@info "$(now()) - CDSAPI - Request is queued"
@info "$(now()) - CDSAPI - Request is queued"; flush(stderr)
sleep_seconds = 1.
while data["state"] == "queued"
data = parserequest(ckeys,resp_dict,apikey)
sleep_seconds = min(1.5 * sleep_seconds,5)
sleep(sleep_seconds)
end

@info "$(now()) - CDSAPI - Request is running"
@info "$(now()) - CDSAPI - Request is running"; flush(stderr)
sleep_seconds = 1.
while data["state"] == "running"
data = parserequest(ckeys,resp_dict,apikey)
Expand All @@ -51,14 +51,15 @@ function retrieve(

if data["state"] == "completed"

@info "$(now()) - CDSAPI - Request is completed"
@info "$(now()) - CDSAPI - Request is completed"; flush(stderr)

sleep(10)

@info """$(now()) - CDSAPI - Downloading $(uppercase(dset)) data ...
URL: $(data["location"])
Destination: $(fnc)
"""
flush(stderr)

tries = 0
while isinteger(tries) && (tries < 10)
Expand All @@ -72,6 +73,7 @@ function retrieve(
tries += 1
@info "$(now()) - CDSAPI - Failed to download on Attempt $(tries) of 10"
end
flush(stderr)
end

if tries == 10
Expand All @@ -84,6 +86,8 @@ function retrieve(

end

flush(stderr)

return

end
Expand Down
4 changes: 4 additions & 0 deletions src/downloads/downloads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ function downloadcheckevar(

@info "$(modulelog()) - The ERA5Variable ID \"$(evar.ID)\" is a valid ERA5 Variable identifier and therefore can be used to download data from the Climate Data Store"

flush(stderr)

else

error("$(modulelog()) - The ERA5Variable ID \"$(evar.ID)\" is a custom ERA5 Variable identifier and therefore cannot be used to download data from the Climate Data Store, and can only be calculated/analyzed from preexisting valid ERA5 data")
Expand Down Expand Up @@ -187,6 +189,8 @@ function downloadcheckplvl(
pvec = []
end

flush(stderr)

return pvec

end

0 comments on commit e880ac2

Please sign in to comment.