BenchmarkAnything-Storage-Frontend-Lib

 view release on metacpan or  search on metacpan

lib/BenchmarkAnything/Storage/Frontend/Lib.pm  view on Meta::CPAN

                my $result = $res->json;

                # output
                return $result;
        }
        else
        {
                die "benchmarkanything: no backend '$backend', available backends are: 'http', 'local'.\n";
        }
}


sub stats
{
        my ($self) = @_;

        my $backend = $self->{config}{benchmarkanything}{backend};
        if ($backend eq 'local')
        {
                return $self->{backend}->get_stats;
        }
        elsif ($backend eq 'http')
        {
                my $ua  = $self->_get_user_agent;
                my $url = $self->_get_base_url."/api/v1/stats";

                my $res = $ua->get($url)->res;
                die "benchmarkanything: ".$res->error->{message}." ($url)\n" if $res->error;

                my $result = $res->json;

                # output
                return $result;
        }
        else
        {
                die "benchmarkanything: no backend '$backend', available backends are: 'http', 'local'.\n";
        }
}


sub gc
{
        my ($self) = @_;

        my $backend = $self->{config}{benchmarkanything}{backend};
        if ($backend eq 'local')
        {
                $self->{backend}->gc;
        }
}


sub process_raw_result_queue
{
        my ($self, $count) = @_;

        require LockFile::Simple;

        my $lock;
        my $lockmgr = LockFile::Simple->make(-stale => 1, -autoclean => 1);

        return unless $lock = $lockmgr->trylock('/tmp/process_raw_result_queue');

        $count ||= 10;

        my $backend = $self->{config}{benchmarkanything}{backend};
        if ($backend eq 'local')
        {
                my @dequeued_raw_bench_bundle_ids;
                do {
                        @dequeued_raw_bench_bundle_ids = $self->{backend}->process_queued_multi_benchmark($count);
                        #print STDERR "Processed bench_bundles: ".join(",", @dequeued_raw_bench_bundle_ids)."\n" if $self->{verbose};
                        $count = $count - @dequeued_raw_bench_bundle_ids;
                } until ($count < 1 or not @dequeued_raw_bench_bundle_ids);
        }
        else
        {
                $lock->release;
                die "benchmarkanything: only backend 'local' allowed in 'process_raw_result_queue'.\n";
        }

        $lock->release;
        return;
}


sub init_search_engine
{
        my ($self, $force) = @_;

        my $backend = $self->{config}{benchmarkanything}{backend};
        if ($backend eq 'local')
        {
                $self->{backend}->init_search_engine($force);
        }
        else
        {
                die "benchmarkanything: only backend 'local' allowed in 'init_search_engine'.\n";
        }
        return;
}


sub sync_search_engine
{
        my ($self, $force, $start, $count) = @_;

        my $backend = $self->{config}{benchmarkanything}{backend};
        if ($backend eq 'local')
        {
                $self->{backend}->sync_search_engine($force, $start, $count);
        }
        else
        {
                die "benchmarkanything: only backend 'local' allowed in 'sync_search_engine'.\n";
        }
        return;
}




( run in 0.749 second using v1.01-cache-2.11-cpan-df04353d9ac )