Add Gearman decode worker
authorVincent Tondellier <tonton+hg@team1664.org>
Sat, 06 Apr 2013 22:50:55 +0200
changeset 18 60db1090095b
parent 17 c91535b1db3e
child 19 300b902b5461
Add Gearman decode worker
bin/gearman_decode_worker.pl
lib/CrashTest/Decode/Queue/Gearman.pm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/gearman_decode_worker.pl	Sat Apr 06 22:50:55 2013 +0200
@@ -0,0 +1,50 @@
+#!/usr/bin/env perl
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use Gearman::Worker;
+use Mojo::JSON;
+use Mojo::Util qw(decode slurp);
+use File::Temp;
+
+sub load_config {
+    my ($file) = @_;
+    my $code = decode('UTF-8', slurp $file);
+    return eval($code);
+}
+
+my $config = load_config($ARGV[0]);
+my $worker = Gearman::Worker->new(job_servers => $config->{GearmanServers});
+
+$worker->register_function("dump_decode", 60, sub {
+    my $args = $_[0]->arg;
+
+    my $json = Mojo::JSON->new();
+    my $jsonin = $json->decode($args);
+
+    my $file = File::Temp->new();
+    print $file $jsonin->{file};
+
+    my $cmd = $config->{MinidumpStackwalkJSON} . " " . $file->filename . " " . $config->{SymbolsPath};
+    my $out = qx($cmd 2>/dev/null) or die $!;
+
+    my $pjson = $json->decode($out);
+
+    # Create json for the params
+    $pjson->{client_info} = $jsonin->{params};
+
+    return $json->encode($pjson);
+});
+
+$worker->work() while 1;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/CrashTest/Decode/Queue/Gearman.pm	Sat Apr 06 22:50:55 2013 +0200
@@ -0,0 +1,45 @@
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package CrashTest::Decode::Queue::Gearman;
+
+use Gearman::Client;
+
+use strict;
+use warnings;
+
+sub new {
+    my ($class, $config) = @_;
+    my $self  = {};
+    $self->{config} = $config;
+    $self->{gearman} = Gearman::Client->new(job_servers => $config->{GearmanServers});
+    bless ($self, $class);
+    return $self;
+}
+
+sub config {
+    my ($self, $key) = @_;
+    return $self->{config}->{$key};
+}
+
+sub decode {
+    my ($self, $file, $paramshash) = @_;
+
+    my $json = Mojo::JSON->new;
+    my $args = $json->encode({ file => $file->slurp, params => $paramshash });
+    my $taskres = $self->{gearman}->do_task('dump_decode', $args);
+
+    return $json->decode($$taskres);
+}
+
+1;