bin/gearman_decode_worker.pl
author Vincent Tondellier <tonton+hg@team1664.org>
Sat, 06 Apr 2013 22:50:55 +0200
changeset 18 60db1090095b
child 19 300b902b5461
permissions -rwxr-xr-x
Add Gearman decode worker
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     1
#!/usr/bin/env perl
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     2
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     3
# This program is free software: you can redistribute it and/or modify
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     4
# it under the terms of the GNU General Public License as published by
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     5
# the Free Software Foundation, either version 3 of the License, or
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     6
# (at your option) any later version.
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     7
#
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     8
# This program is distributed in the hope that it will be useful,
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    11
# GNU General Public License for more details.
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    12
#
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    13
# You should have received a copy of the GNU General Public License
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    15
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    16
use Gearman::Worker;
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    17
use Mojo::JSON;
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    18
use Mojo::Util qw(decode slurp);
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    19
use File::Temp;
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    20
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    21
sub load_config {
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    22
    my ($file) = @_;
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    23
    my $code = decode('UTF-8', slurp $file);
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    24
    return eval($code);
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    25
}
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    26
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    27
my $config = load_config($ARGV[0]);
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    28
my $worker = Gearman::Worker->new(job_servers => $config->{GearmanServers});
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    29
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    30
$worker->register_function("dump_decode", 60, sub {
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    31
    my $args = $_[0]->arg;
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    32
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    33
    my $json = Mojo::JSON->new();
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    34
    my $jsonin = $json->decode($args);
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    35
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    36
    my $file = File::Temp->new();
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    37
    print $file $jsonin->{file};
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    38
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    39
    my $cmd = $config->{MinidumpStackwalkJSON} . " " . $file->filename . " " . $config->{SymbolsPath};
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    40
    my $out = qx($cmd 2>/dev/null) or die $!;
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    41
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    42
    my $pjson = $json->decode($out);
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    43
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    44
    # Create json for the params
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    45
    $pjson->{client_info} = $jsonin->{params};
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    46
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    47
    return $json->encode($pjson);
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    48
});
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    49
60db1090095b Add Gearman decode worker
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    50
$worker->work() while 1;