Skip to content

Commit

Permalink
Slightly better logging experience. (#61)
Browse files Browse the repository at this point in the history
* Adds a slightly better logging experience.

* fix: remove last set of points before download info

* fix: remove gimmick progress bar, expand Dates compat version.

* Improve info message and code formatting

* Improve info message

---------

Co-authored-by: Júlio Hoffimann <[email protected]>
  • Loading branch information
ghyatzo and juliohm authored Jan 20, 2025
1 parent c07acc5 commit 57d98c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ authors = ["Micky Yun Chan <[email protected]> and contributors"]
version = "2.0.3"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"

[compat]
Dates = "1.11"
HTTP = "1"
JSON = "0.21"
julia = "1"
Expand Down
9 changes: 8 additions & 1 deletion src/CDSAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module CDSAPI

using HTTP
using JSON
using Dates

"""
retrieve(name, params, filename; wait=1.0)
Expand Down Expand Up @@ -52,12 +53,17 @@ function retrieve(name, params::AbstractDict, filename; wait=1.0)
data = JSON.parse(String(response.body))
endpoint = Dict(response.headers)["location"]

laststatus = nothing
while data["status"] != "successful"
data = HTTP.request("GET", endpoint,
["PRIVATE-TOKEN" => creds["key"]]
)
data = JSON.parse(String(data.body))
@info "CDS request" dataset=name status=data["status"]

if data["status"] != laststatus
@info "CDS request update on $(now())" dataset = name status = data["status"]
laststatus = data["status"]
end

if data["status"] == "failed"
throw(ErrorException("""
Expand All @@ -78,6 +84,7 @@ function retrieve(name, params::AbstractDict, filename; wait=1.0)
["PRIVATE-TOKEN" => creds["key"]]
)
body = JSON.parse(String(response.body))

HTTP.download(body["asset"]["value"]["href"], filename)

return data
Expand Down

0 comments on commit 57d98c9

Please sign in to comment.