Skip to content

Instantly share code, notes, and snippets.

@monken
Created July 20, 2011 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monken/1094658 to your computer and use it in GitHub Desktop.
Save monken/1094658 to your computer and use it in GitHub Desktop.
use IO::Async::Timer::Periodic;
use strict;
use warnings;
use IO::Async::Loop;
use LWP::UserAgent;
use HTTP::Request::Common qw(HEAD);
my $ua = LWP::UserAgent->new;
my $loop = IO::Async::Loop->new();
my $code = 0;
my $timer = IO::Async::Timer::Periodic->new(
interval => 10,
first_interval => 0,
on_tick => sub {
my $res = $ua->request( HEAD "http://store.apple.com" );
return if($res->code, $code);
$code = $res->code;
if($code == 404) {
`say "Apple Store is down!"`;
} else {
`say "Apple Store back up!"`;
}
},
);
$timer->start;
$loop->add($timer);
$loop->loop_forever;
@dolmen
Copy link

dolmen commented Jul 20, 2011

See my AnyEvent-based version of this script at https://gist.github.com/1094704

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment