Skip to content

Commit

Permalink
Use JobFunnel::Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Maischein committed Jun 1, 2024
1 parent 17f12f4 commit d5d3771
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/COWS/Crawler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,23 @@ sub submit_request( $self, $request ) {
my $queued = { req => $req, info => $info };
push $self->queue->@*, $queued;

my $progress = JobFunnel::ProgressItem->new(
visual => $url,
total => undef,
);

$req->res->on( 'progress' => sub($res,@rest) {
$s->emit('progress', $queued, $res);
return unless my $len = $res->headers->content_length;
$progress->total($len) unless defined $progress->total;
$progress->progress($res->content->progress);
});
$req->res->on( 'finish' => sub($res,@rest) {
$s->emit('finish', $queued, $res);
$progress->finish();
});

return $queued
return $progress
}

# do we want push/unshift, to manage the expansion
Expand All @@ -252,6 +261,11 @@ sub submit_download( $self, $request, $filename ) {

weaken (my $s = $self);

my $progress = JobFunnel::ProgressItem->new(
visual => $url,
total => undef,
);

# See also LWP::UserAgent
# If the file exists, add a cache-related header
if ( -e $filename ) {
Expand All @@ -265,6 +279,7 @@ sub submit_download( $self, $request, $filename ) {
my $queued = { req => $req, info => $info };
$req->res->on( 'progress' => sub($res,@rest) {
$s->emit('progress', $queued, $res);
$progress->progress($res->content->progress);
});
$req->res->on( 'finish' => sub($res,@rest) {

Expand All @@ -285,11 +300,12 @@ sub submit_download( $self, $request, $filename ) {
warn sprintf "Got %d status for $url", $res->code;
}
$s->emit('finish', $queued, $res);
$progress->finish();
});

push $self->queue->@*, $queued;

return $queued
return $progress
}


Expand Down

0 comments on commit d5d3771

Please sign in to comment.