# HG changeset patch # User Vincent Tondellier # Date 1406756999 -7200 # Node ID e621317229f780ee9315111a4096e736e14d6dc7 # Parent 768aa027e7cbc4860c684980ba4f0320b0f0a628 Async submit. Requires AnyEvent::Gearman diff -r 768aa027e7cb -r e621317229f7 CrashTest.pl --- a/CrashTest.pl Wed Jun 25 00:16:17 2014 +0200 +++ b/CrashTest.pl Wed Jul 30 23:49:59 2014 +0200 @@ -31,7 +31,7 @@ app->attr(decode_queue => sub { my $self = shift; - eval "require $config->{DecodeQueue}->{Type}"; + eval "require $config->{DecodeQueue}->{Type}" or die "Loading module failed $@"; return $config->{DecodeQueue}->{Type}->new($config->{DecodeQueue}, $config->{Dumper}, app->storage); }); @@ -98,11 +98,19 @@ my ($uuid, $uuidstr); UUID::generate($uuid); UUID::unparse($uuid, $uuidstr); - my $pjson = $self->app->decode_queue->decode($file, \%paramshash, $uuidstr); + + $self->render_later(); - # reply - $self->render_text($pjson->{status}); + $self->app->decode_queue->decode($file, \%paramshash, $uuidstr, sub { + my $pjson = shift; + # reply + $self->render(text => $pjson->{status}); + } + ); + }; -app->secret('My secret passphrase here'); +app->secrets([ + 'My secret passphrase here' +]); app->start; diff -r 768aa027e7cb -r e621317229f7 lib/CrashTest/Decode/Queue/Gearman.pm --- a/lib/CrashTest/Decode/Queue/Gearman.pm Wed Jun 25 00:16:17 2014 +0200 +++ b/lib/CrashTest/Decode/Queue/Gearman.pm Wed Jul 30 23:49:59 2014 +0200 @@ -13,7 +13,7 @@ package CrashTest::Decode::Queue::Gearman; -use Gearman::Client; +use AnyEvent::Gearman::Client; use strict; use warnings; @@ -21,19 +21,25 @@ sub new { my ($class, $config, $dumperconfig, $storage) = @_; my $self = {}; - $self->{gearman} = Gearman::Client->new(job_servers => $config->{GearmanServers}); + $self->{gearman} = AnyEvent::Gearman::Client->new(job_servers => $config->{GearmanServers}); bless ($self, $class); return $self; } sub decode { - my ($self, $file, $paramshash, $uuidstr) = @_; + my ($self, $file, $paramshash, $uuidstr, $cb) = @_; my $json = Mojo::JSON->new; my $args = $json->encode({ file => $file->slurp, params => $paramshash, uuid => $uuidstr }); - my $taskres = $self->{gearman}->do_task('dump_decode', $args); - - return $json->decode($$taskres); + $self->{gearman}->add_task( + dump_decode => $args, + on_complete => sub { + my $taskres = $_[1]; + &$cb($json->decode($taskres)); + }, + on_fail => sub { + } + ); } 1; diff -r 768aa027e7cb -r e621317229f7 lib/CrashTest/Decode/Queue/NoQueue.pm --- a/lib/CrashTest/Decode/Queue/NoQueue.pm Wed Jun 25 00:16:17 2014 +0200 +++ b/lib/CrashTest/Decode/Queue/NoQueue.pm Wed Jul 30 23:49:59 2014 +0200 @@ -28,7 +28,7 @@ } sub decode { - my ($self, $file, $paramshash, $uuidstr) = @_; + my ($self, $file, $paramshash, $uuidstr, $cb) = @_; my $fh = File::Temp->new(SUFFIX => '.dmp'); my $dmp_file = $fh->filename; $file->move_to($dmp_file); @@ -45,7 +45,7 @@ $self->{storage}->store_dump($uuidstr, $file->slurp); $self->{storage}->store_processed_data($uuidstr, $pjson); - return $pjson; + &$cb($pjson); } 1;