bin/gearman_decode_worker.pl
changeset 18 60db1090095b
child 19 300b902b5461
equal deleted inserted replaced
17:c91535b1db3e 18:60db1090095b
       
     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 Gearman::Worker;
       
    17 use Mojo::JSON;
       
    18 use Mojo::Util qw(decode slurp);
       
    19 use File::Temp;
       
    20 
       
    21 sub load_config {
       
    22     my ($file) = @_;
       
    23     my $code = decode('UTF-8', slurp $file);
       
    24     return eval($code);
       
    25 }
       
    26 
       
    27 my $config = load_config($ARGV[0]);
       
    28 my $worker = Gearman::Worker->new(job_servers => $config->{GearmanServers});
       
    29 
       
    30 $worker->register_function("dump_decode", 60, sub {
       
    31     my $args = $_[0]->arg;
       
    32 
       
    33     my $json = Mojo::JSON->new();
       
    34     my $jsonin = $json->decode($args);
       
    35 
       
    36     my $file = File::Temp->new();
       
    37     print $file $jsonin->{file};
       
    38 
       
    39     my $cmd = $config->{MinidumpStackwalkJSON} . " " . $file->filename . " " . $config->{SymbolsPath};
       
    40     my $out = qx($cmd 2>/dev/null) or die $!;
       
    41 
       
    42     my $pjson = $json->decode($out);
       
    43 
       
    44     # Create json for the params
       
    45     $pjson->{client_info} = $jsonin->{params};
       
    46 
       
    47     return $json->encode($pjson);
       
    48 });
       
    49 
       
    50 $worker->work() while 1;