@@ -8,6 +8,7 @@ use Mojo::URL;
8
8
use Mojolicious::Types;
9
9
use Mojolicious::Plugin::AssetPack::Asset;
10
10
use Mojolicious::Plugin::AssetPack::Util qw( diag checksum has_ro DEBUG) ;
11
+ use Time::HiRes qw( sleep) ;
11
12
12
13
use constant CACHE_DIR => ' cache' ;
13
14
@@ -26,6 +27,8 @@ has asset_class => 'Mojolicious::Plugin::AssetPack::Asset';
26
27
has default_headers => sub { +{" Cache-Control" => " max-age=31536000" } };
27
28
has fallback_headers => sub { +{" Cache-Control" => " max-age=60" } };
28
29
has fallback_templates => sub { +{%FALLBACK_TEMPLATES } };
30
+ has retry_delay => 3;
31
+ has retries => 0;
29
32
30
33
has _types => sub {
31
34
my $t = Mojolicious::Types-> new;
@@ -257,14 +260,22 @@ sub _download {
257
260
258
261
return $asset if $attrs {url }-> host ne ' local' and $asset = $self -> _already_downloaded($url );
259
262
260
- my $tx = $self -> ua-> get($url );
261
- my $h = $tx -> res-> headers;
263
+ my $tx ;
264
+ my $retries = $self -> retries;
265
+ while (1) {
266
+ $tx = $self -> ua-> get($url );
267
+ last unless my $err = $tx -> error;
268
+
269
+ if ($retries -- > 0) {
270
+ sleep $self -> retry_delay;
271
+ next ;
272
+ }
262
273
263
- if (my $err = $tx -> error) {
264
274
$self -> _log-> warn (" [AssetPack] Unable to download $url : $err ->{message}" );
265
275
return undef ;
266
276
}
267
277
278
+ my $h = $tx -> res-> headers;
268
279
my $ct = $h -> content_type || ' ' ;
269
280
if ($ct ne ' text/plain' ) {
270
281
$ct =~ s ! ;.*$!! ;
@@ -388,6 +399,20 @@ This is currently an EXPERIMENTAL feature.
388
399
389
400
See L<Mojolicious::Static/paths> for details.
390
401
402
+ =head2 retry_delay
403
+
404
+ my $delay = $self->retry_delay;
405
+ $self = $self->retry_delay(0.5);
406
+
407
+ Delay in seconds between download attempts for assets that need to be fetched, defaults to C<3 > .
408
+
409
+ =head2 retries
410
+
411
+ my $retries = $self->retries;
412
+ $self = $self->retries(5);
413
+
414
+ Number of times asset downloads will be attempted for assets that need to be fetched, defaults to C<0 > .
415
+
391
416
=head2 ua
392
417
393
418
$ua = $self->ua;
0 commit comments