Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1.  
  2. my $max_conn = 100;
  3.  
  4.  
  5. my $query = "SELECT ip FROM intranet_ip";
  6. my $res = $db->query($query);
  7. my @urls = Mojo::URL->new();
  8. my @allUrls;
  9. while ( my $row = $res->hash ) {
  10.  
  11. my $pgsql_ip = $row->{ip};
  12. push @allUrls, $pgsql_ip;
  13. }
  14.  
  15. my $ua = Mojo::UserAgent->new( max_redirects => 5 );
  16.  
  17. my $active = 0;
  18. Mojo::IOLoop->recurring(
  19. 0 => sub {
  20. for ( $active + 1 .. $max_conn ) {
  21.  
  22. return ( $active or Mojo::IOLoop->stop )
  23. unless my $url = shift @urls;
  24.  
  25. ++$active;
  26. $ua->get( $url => \&get_callback );
  27. }
  28. }
  29. );
  30.  
  31. sub get_callback {
  32. my ( undef, $tx ) = @_;
  33.  
  34. --$active;
  35. my $url = $tx->req->url;
  36.  
  37. if ( ( !$tx->res->is_status_class(200) )
  38. or ( $tx->res->headers->content_type !~ m{^text/html\b}ix ) )
  39. {
  40. say "url getting problem: $url";
  41. return;
  42. }
  43.  
  44. #say $url;
  45.  
  46. return;
  47. }
  48.  
  49. for my $href (@allUrls) {
  50. my $origUrl = $href;
  51. @urls = ();
  52. push( @urls, Mojo::URL->new($origUrl) );
  53. $active = 0;
  54. say "Processing: $href";
  55. ### Start event loop if necessary
  56. Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement