Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
d3970926
You need to sign in or sign up before continuing.
Commit
d3970926
authored
Nov 02, 2023
by
Michael Yang
Browse files
download with retry
parent
60bb3c03
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
18 deletions
+3
-18
server/download.go
server/download.go
+2
-7
server/images.go
server/images.go
+1
-11
No files found.
server/download.go
View file @
d3970926
...
@@ -89,17 +89,12 @@ func (b *blobDownload) Prepare(ctx context.Context, requestURL *url.URL, opts *R
...
@@ -89,17 +89,12 @@ func (b *blobDownload) Prepare(ctx context.Context, requestURL *url.URL, opts *R
}
}
if
len
(
b
.
Parts
)
==
0
{
if
len
(
b
.
Parts
)
==
0
{
resp
,
err
:=
makeRequest
(
ctx
,
http
.
MethodHead
,
requestURL
,
nil
,
nil
,
opts
)
resp
,
err
:=
makeRequest
WithRetry
(
ctx
,
http
.
MethodHead
,
requestURL
,
nil
,
nil
,
opts
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
if
resp
.
StatusCode
>=
http
.
StatusBadRequest
{
body
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
return
fmt
.
Errorf
(
"registry responded with code %d: %v"
,
resp
.
StatusCode
,
string
(
body
))
}
b
.
Total
,
_
=
strconv
.
ParseInt
(
resp
.
Header
.
Get
(
"Content-Length"
),
10
,
64
)
b
.
Total
,
_
=
strconv
.
ParseInt
(
resp
.
Header
.
Get
(
"Content-Length"
),
10
,
64
)
var
size
=
b
.
Total
/
numDownloadParts
var
size
=
b
.
Total
/
numDownloadParts
...
@@ -199,7 +194,7 @@ func (b *blobDownload) run(ctx context.Context, requestURL *url.URL, opts *Regis
...
@@ -199,7 +194,7 @@ func (b *blobDownload) run(ctx context.Context, requestURL *url.URL, opts *Regis
func
(
b
*
blobDownload
)
downloadChunk
(
ctx
context
.
Context
,
requestURL
*
url
.
URL
,
w
io
.
Writer
,
part
*
blobDownloadPart
,
opts
*
RegistryOptions
)
error
{
func
(
b
*
blobDownload
)
downloadChunk
(
ctx
context
.
Context
,
requestURL
*
url
.
URL
,
w
io
.
Writer
,
part
*
blobDownloadPart
,
opts
*
RegistryOptions
)
error
{
headers
:=
make
(
http
.
Header
)
headers
:=
make
(
http
.
Header
)
headers
.
Set
(
"Range"
,
fmt
.
Sprintf
(
"bytes=%d-%d"
,
part
.
StartsAt
(),
part
.
StopsAt
()
-
1
))
headers
.
Set
(
"Range"
,
fmt
.
Sprintf
(
"bytes=%d-%d"
,
part
.
StartsAt
(),
part
.
StopsAt
()
-
1
))
resp
,
err
:=
makeRequest
(
ctx
,
http
.
MethodGet
,
requestURL
,
headers
,
nil
,
opts
)
resp
,
err
:=
makeRequest
WithRetry
(
ctx
,
http
.
MethodGet
,
requestURL
,
headers
,
nil
,
opts
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
server/images.go
View file @
d3970926
...
@@ -1120,22 +1120,12 @@ func pullModelManifest(ctx context.Context, mp ModelPath, regOpts *RegistryOptio
...
@@ -1120,22 +1120,12 @@ func pullModelManifest(ctx context.Context, mp ModelPath, regOpts *RegistryOptio
headers
:=
make
(
http
.
Header
)
headers
:=
make
(
http
.
Header
)
headers
.
Set
(
"Accept"
,
"application/vnd.docker.distribution.manifest.v2+json"
)
headers
.
Set
(
"Accept"
,
"application/vnd.docker.distribution.manifest.v2+json"
)
resp
,
err
:=
makeRequest
(
ctx
,
http
.
MethodGet
,
requestURL
,
headers
,
nil
,
regOpts
)
resp
,
err
:=
makeRequest
WithRetry
(
ctx
,
http
.
MethodGet
,
requestURL
,
headers
,
nil
,
regOpts
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"couldn't get manifest: %v"
,
err
)
return
nil
,
err
return
nil
,
err
}
}
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
if
resp
.
StatusCode
>=
http
.
StatusBadRequest
{
if
resp
.
StatusCode
==
http
.
StatusNotFound
{
return
nil
,
fmt
.
Errorf
(
"model not found"
)
}
body
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
return
nil
,
fmt
.
Errorf
(
"on pull registry responded with code %d: %s"
,
resp
.
StatusCode
,
body
)
}
var
m
*
ManifestV2
var
m
*
ManifestV2
if
err
:=
json
.
NewDecoder
(
resp
.
Body
)
.
Decode
(
&
m
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
resp
.
Body
)
.
Decode
(
&
m
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment