lib/CrashTest/Decode/Queue/Gearman.pm
author Vincent Tondellier <tonton+hg@team1664.org>
Thu, 07 Aug 2014 23:50:08 +0200
changeset 34 e0d6597078a5
parent 27 2b158020f0d5
child 54 2218a127abd9
permissions -rw-r--r--
Cleanup: Mojo-ize old code, simplifying perl OO code Make Sql Storage inherit Filesystem, since the DB is only used as an index and still stores on disk

# 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 Mojo::Base -base;
use Gearman::Client;

has [ qw/config gearman/ ];

sub new {
    my $self = shift->SUPER::new(@_);

    $self->gearman(Gearman::Client->new(
            job_servers => $self->config->{GearmanServers})
    );

    return $self;
}

sub decode {
    my ($self, $file, $paramshash, $uuidstr, $cb) = @_;

    my $json = Mojo::JSON->new;
    my $args = $json->encode(
        {
            file    => $file->slurp,
            params  => $paramshash,
            uuid    => $uuidstr
        }
    );

    $self->gearman->dispatch_background('dump_decode', $args);

    $cb->({ status => "backgrounded" });
}

1;