Browse Source

some more complex failure management

themage
theMage 4 years ago
parent
commit
347b7d4808
1 changed files with 22 additions and 17 deletions
  1. 22 17
      lib/CinePantufas/Core.pm

+ 22 - 17
lib/CinePantufas/Core.pm

@ -338,26 +338,31 @@ sub __queue_new {
338 338
  EPISODE:
339 339
  for my $k (sort keys %epidb) {
340 340
    my $episode = from_json($epidb{$k}, {utf8=>1});
341
    if ($episode->{status} eq 'failed' and rand(20)>19) {
342
      $episode->{status} = 'new';
343
      $episode->{failed} = 0;
344
    }
341 345
    next unless $episode->{status} eq 'new';
342 346
343
    my $link = ${$episode->{torrents}}[
344
        rand(scalar @{$episode->{torrents}})
345
      ];
346
347
    for my $hook (@{ $hooks{add_torrent}||[] }) {
348
      my $cls = $hook->{class};
349
      my $handler = $hook->{handler};
350
      my $res = $handler->($cls, $link);
351
352
      if ( $res and $res->{status} eq 'ok') {
353
        $episode->{status} = 'queued';
354
        $episode->{hashString} = $res->{hashString}
355
          if $res->{hashString};
356
        $epidb{$k} = to_json($episode,{utf8=>1});
357
        $queued++;
358
359
        next EPISODE;
347
    for my $link (@{$episode->{torrents}} ) {
348
      next if $link ~= m{(www.bt-chat.com|DOCTYPE)};
349
      
350
      for my $hook (@{ $hooks{add_torrent}||[] }) {
351
        my $cls = $hook->{class};
352
        my $handler = $hook->{handler};
353
        my $res = $handler->($cls, $link);
354
355
        if ( $res and $res->{status} eq 'ok') {
356
          $episode->{status} = 'queued';
357
          $episode->{hashString} = $res->{hashString}
358
            if $res->{hashString};
359
          $epidb{$k} = to_json($episode,{utf8=>1});
360
          $queued++;
361
362
         next EPISODE;
363
        }
360 364
      }
365
361 366
    }
362 367
363 368
    $episode->{failed}++;