Skip to content

Commit

Permalink
Implement build salvage routines
Browse files Browse the repository at this point in the history
If a new build of a dist that"s already in the db fails (e.g. due to network errors), we need to catch that and update the Build ID in the database for that dist, so that it does not get purged as a removed dist at the end of the build process.
  • Loading branch information
zoffixznet committed Nov 28, 2015
1 parent 76cc2d0 commit d69411a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/ModulesPerl6/DbBuilder/Dist.pm
Expand Up @@ -43,11 +43,14 @@ sub _load_from_source {
for my $source ( $self->_sources ) {
next unless $url =~ $source->re;
log info => "Using $source to load $url";
my $dist = $source->new(
my $dist_source = $source->new(
meta_url => $url,
logos_dir => $self->_logos_dir,
dist_db => $self->_dist_db,
)->load or return;
)
my $dist = $dist_source->load
return $self->_salvage_build( $dist_source );

$dist->{build_id} = $self->_build_id;

for my $postprocessor ( $self->_postprocessors ) {
Expand All @@ -67,4 +70,14 @@ sub _load_from_source {
return;
}

sub _salvage_build {
my ( $self, $dist_source ) = @_;

my $dist = $dist_source->_dist;
$self->_dist_db->salvage_build( $dist->{url}, $self->_build_id )
if ref $dist and length $dist->{url};

return;
}

1;
10 changes: 10 additions & 0 deletions lib/ModulesPerl6/Model/Dists.pm
Expand Up @@ -111,6 +111,16 @@ sub remove_old {
$num_deleted;
}

sub salvage_build {
my ( $self, $url, $new_build_id ) = @_;
return unless length $url and length $new_build_id;

$self->_db->resultset('Dist')->search({ url => $url })
->update_all({ build_id => $new_build_id });

return 1;
}

1;

__END__
Expand Down

0 comments on commit d69411a

Please sign in to comment.