Created
August 10, 2011 21:13
-
-
Save bklaas/1138287 to your computer and use it in GitHub Desktop.
A demo script for running a sprint and/or rush using the CPAN module Blitz
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
#!/usr/bin/perl | |
use strict; | |
$| = 1; | |
use Blitz; | |
use Data::Dumper; | |
my $blitz = Blitz->new( { | |
username => '[email protected]', | |
api_key => 'login to http://blitz.io to get your api key', | |
} | |
); | |
my $options = { | |
pattern => { | |
iterations => 1, | |
intervals => [ | |
{ iterations => 1, start => 1, end => 100, duration => 30 }, | |
], | |
}, | |
url => 'http://yourcoolapp/someroute?iterate=#{iterate}', | |
variables => { | |
iterate => { type => 'number', min => 2, max => 4 }, | |
}, | |
region => 'california', | |
}; | |
# sprint | |
$blitz->sprint( $options, \&callback ); | |
# or rush | |
$blitz->rush( $options, \&callback ); | |
sub callback { | |
my ($ok, $err) = @_; | |
print "=-=-=-=-=-=-=-=-=-\n"; | |
if ($err) { | |
print STDERR "ERROR!\n"; | |
print Dumper $err; | |
} | |
else { | |
print Dumper $ok; | |
} | |
print "=-=-=-=-=-=-=-=-=-\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a demonstration script for using the CPAN Perl module Blitz (on github as blitz-perl). User needs to edit the file's user, api-key, and url parameters to suit their purpose, but otherwise this script will work.
Note that the callback closure pulls in both $ok (a hash ref with response data) and $err (an error hash ref, if there was an error)