Skip to content

Instantly share code, notes, and snippets.

@monken
Created December 29, 2011 18:44
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/1535522 to your computer and use it in GitHub Desktop.
Save monken/1535522 to your computer and use it in GitHub Desktop.
use Net::RabbitMQ;
use strict;
use warnings;
use JSON::XS;
use IPC::Run3;
my $mq = Net::RabbitMQ->new();
$mq->connect( "localhost", {} );
$mq->channel_open(1);
$mq->consume( 1, "myapp.jobs", { no_ack => 0 } );
while (1) {
my $msg = $mq->recv;
my $body = decode_json( $msg->{body} );
print " [*] Processing $body->{id}", $/;
run3 [ './bin/wkhtmltopdf-amd64', '-q', $body->{url}, "var/$body->{id}.pdf" ];
$mq->publish( 1, $body->{reply_to},
encode_json( { uri => "$body->{id}.pdf" } ) );
$mq->ack( 1, $msg->{delivery_tag} );
print "\t[x] done", $/ x 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment