bin/gearman_decode_worker.pl
changeset 19 300b902b5461
parent 18 60db1090095b
child 20 169c73eb8881
equal deleted inserted replaced
18:60db1090095b 19:300b902b5461
    15 
    15 
    16 use Gearman::Worker;
    16 use Gearman::Worker;
    17 use Mojo::JSON;
    17 use Mojo::JSON;
    18 use Mojo::Util qw(decode slurp);
    18 use Mojo::Util qw(decode slurp);
    19 use File::Temp;
    19 use File::Temp;
       
    20 use lib 'lib';
    20 
    21 
    21 sub load_config {
    22 sub load_config {
    22     my ($file) = @_;
    23     my ($file) = @_;
    23     my $code = decode('UTF-8', slurp $file);
    24     my $code = decode('UTF-8', slurp $file);
    24     return eval($code);
    25     return eval($code);
    25 }
    26 }
    26 
    27 
    27 my $config = load_config($ARGV[0]);
    28 my $config = load_config($ARGV[0]);
    28 my $worker = Gearman::Worker->new(job_servers => $config->{GearmanServers});
    29 
       
    30 eval "require $config->{Storage}->{Type}";
       
    31 my $storage = $config->{Storage}->{Type}->new($config->{Storage});
       
    32 
       
    33 my $worker = Gearman::Worker->new(job_servers => $config->{DecodeQueue}->{GearmanServers});
       
    34 
    29 
    35 
    30 $worker->register_function("dump_decode", 60, sub {
    36 $worker->register_function("dump_decode", 60, sub {
    31     my $args = $_[0]->arg;
    37     my $args = $_[0]->arg;
    32 
    38 
    33     my $json = Mojo::JSON->new();
    39     my $json = Mojo::JSON->new();
    34     my $jsonin = $json->decode($args);
    40     my $jsonin = $json->decode($args);
    35 
    41 
    36     my $file = File::Temp->new();
    42     my $file = File::Temp->new();
       
    43     binmode($file);
    37     print $file $jsonin->{file};
    44     print $file $jsonin->{file};
    38 
    45 
    39     my $cmd = $config->{MinidumpStackwalkJSON} . " " . $file->filename . " " . $config->{SymbolsPath};
    46     my $cmd = $config->{Dumper}->{JSONStackwalker} . " " . $file->filename . " " . $config->{Dumper}->{SymbolsPath};
    40     my $out = qx($cmd 2>/dev/null) or die $!;
    47     my $out = qx($cmd 2>/dev/null) or die $!;
    41 
    48 
    42     my $pjson = $json->decode($out);
    49     my $pjson = $json->decode($out);
    43 
    50 
    44     # Create json for the params
    51     # Create json for the params
    45     $pjson->{client_info} = $jsonin->{params};
    52     $pjson->{client_info} = $jsonin->{params};
    46 
    53 
       
    54     my $uuidstr = $jsonin->{uuid};
       
    55     $storage->store_dump($uuidstr, $file);
       
    56     $storage->store_processed_data($uuidstr, $pjson);
       
    57 
    47     return $json->encode($pjson);
    58     return $json->encode($pjson);
    48 });
    59 });
    49 
    60 
    50 $worker->work() while 1;
    61 $worker->work() while 1;