summary refs log tree commit diff
path: root/lib/githubexplorer
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-02-04 12:13:40 +0100
committerfranck cuny <franck@lumberjaph.net>2010-02-04 12:13:40 +0100
commit8b93c8b6eb054f2ea059a11cd2a10fc4a60c84ad (patch)
tree9bcb6b429d075e13a7b9cf4732a8fb4e030bf5fa /lib/githubexplorer
parentuse a conf file for dbi (diff)
downloadgithub-explorer-8b93c8b6eb054f2ea059a11cd2a10fc4a60c84ad.tar.gz
some error checking
Diffstat (limited to 'lib/githubexplorer')
-rw-r--r--lib/githubexplorer/Profile.pm22
1 files changed, 20 insertions, 2 deletions
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;
 }