bin/gearman_decode_worker.pl
changeset 110 d024bf1f4eab
parent 109 3b95550f4189
child 111 f827f3c50dcf
equal deleted inserted replaced
109:3b95550f4189 110:d024bf1f4eab
     1 #!/usr/bin/env perl
       
     2 
       
     3 # This program is free software: you can redistribute it and/or modify
       
     4 # it under the terms of the GNU General Public License as published by
       
     5 # the Free Software Foundation, either version 3 of the License, or
       
     6 # (at your option) any later version.
       
     7 #
       
     8 # This program is distributed in the hope that it will be useful,
       
     9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    11 # GNU General Public License for more details.
       
    12 #
       
    13 # You should have received a copy of the GNU General Public License
       
    14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    15 
       
    16 use Mojo::Base -strict;
       
    17 use lib 'lib';
       
    18 
       
    19 use Mojo::JSON qw/decode_json/;
       
    20 use Mojo::Util qw/decode slurp/;
       
    21 use Mojo::Loader qw/load_class/;
       
    22 use File::Temp;
       
    23 use Gearman::Worker;
       
    24 use Mojolicious;
       
    25 use Mojo::Home;
       
    26 
       
    27 sub load_config {
       
    28     my $app = Mojolicious->new;
       
    29     $app->home(Mojo::Home->new("$FindBin::Bin/../"));
       
    30     $app->moniker("CrashTest");
       
    31     return $app->plugin('Config');
       
    32 }
       
    33 
       
    34 my $config = load_config();
       
    35 
       
    36 my $storage_class = $config->{Storage}->{Type};
       
    37 if (my $e = load_class($storage_class)) {
       
    38     die ref $e ? "Exception: $e" : 'Not found!';
       
    39 }
       
    40 
       
    41 my $storage = $storage_class->new(config => $config->{Storage});
       
    42 
       
    43 my $worker = Gearman::Worker->new(job_servers => $config->{DecodeQueue}->{GearmanServers});
       
    44 
       
    45 $worker->register_function("dump_decode", 60, sub {
       
    46     my $args = $_[0]->arg;
       
    47 
       
    48     my $jsonin = decode_json($args);
       
    49 
       
    50     my $file = File::Temp->new();
       
    51     binmode($file);
       
    52     print $file $jsonin->{file};
       
    53 
       
    54     my $cmd = $config->{Dumper}->{JSONStackwalker} . " " . $file->filename . " " . $config->{Dumper}->{SymbolsPath};
       
    55     my $out = qx($cmd 2>/dev/null) or die $!;
       
    56 
       
    57     my $pjson = $json->decode($out);
       
    58 
       
    59     # Create json for the params
       
    60     $pjson->{client_info} = $jsonin->{params};
       
    61 
       
    62     my $uuidstr = $jsonin->{uuid};
       
    63     $storage->store_dump($uuidstr, slurp $file);
       
    64     $storage->store_processed_data($uuidstr, $pjson);
       
    65 
       
    66     return $json->encode($pjson);
       
    67 });
       
    68 
       
    69 $worker->work() while 1;