Created
July 20, 2011 09:29
-
-
Save monken/1094658 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See my AnyEvent-based version of this script at https://gist.github.com/1094704