From 8b93c8b6eb054f2ea059a11cd2a10fc4a60c84ad Mon Sep 17 00:00:00 2001 From: franck cuny Date: Thu, 4 Feb 2010 12:13:40 +0100 Subject: some error checking --- lib/githubexplorer/Profile.pm | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'lib/githubexplorer') diff --git a/lib/githubexplorer/Profile.pm b/lib/githubexplorer/Profile.pm index 11b16ca..a2a0b2b 100644 --- a/lib/githubexplorer/Profile.pm +++ b/lib/githubexplorer/Profile.pm @@ -2,6 +2,7 @@ package githubexplorer::Profile; use 5.010; use Moose::Role; use Net::GitHub::V2::Users; +use Try::Tiny; has banned_profiles => ( isa => 'ArrayRef', is => 'ro', default => sub { [qw/gitpan/] } ); @@ -11,6 +12,7 @@ has profiles_to_skip => sub fetch_profile { my ( $self, $login, $depth ) = @_; + say "-> start $login ..."; return if grep { $_ =~ /$login/i } @{ $self->banned_profiles }; return if grep { $_ =~ /$login/i } @{ $self->profiles_to_skip }; @@ -25,6 +27,10 @@ sub fetch_profile { if ( !$profile ) { my $followers = $github->followers(); sleep(1); + if (!$followers || ref $followers ne 'ARRAY') { + sleep(60); + return; + } return if scalar @$followers < 2; say "fetch profile for $login ($depth) ..."; sleep(1); @@ -34,6 +40,7 @@ sub fetch_profile { $self->fetch_profile($login, $depth); } $profile = $self->_create_profile( $login, $github->show, $depth ); + return if !$profile; sleep(2); if ( $self->with_repo ) { $self->fetch_repositories( $profile, $github->list ); @@ -43,9 +50,14 @@ sub fetch_profile { if ( !$profile->done ) { my $local_depth = $depth + 1; # my $followers = $github->followpers(); -# sleep(1); + sleep(1); my $following = $github->following(); + if (!$following || ref $following ne 'ARRAY') { + sleep(60); + return; + } + # foreach my $f (@$followers) { # say $to->login . " is followed by " . $from; # $self->_create_relation($f, $profile, $local_depth); @@ -113,14 +125,20 @@ sub _create_profile { $profile->{depth} = $depth; - my $profile_rs; + my $profile_rs; my $err; + try { $self->schema->txn_do( sub { $profile_rs = $self->schema->resultset('Profiles')->create($profile); } ); +}catch{ + warn $_; + $err = 1; +}; +return if $err; say '-> '.$profile_rs->login . "'s profile created"; return $profile_rs; } -- cgit 1.4.1