Skip to content

Instantly share code, notes, and snippets.

@bklaas
Created August 10, 2011 21:13
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 bklaas/1138287 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/perl
use strict;
$| = 1;
use Blitz;
use Data::Dumper;
my $blitz = Blitz->new( {
username => 'yourusername@gmail.com',
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";
}
}
@bklaas
Copy link
Author

bklaas commented Aug 10, 2011

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)

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