| 1 | 3 | ▶ | use 5.008; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | package BenchmarkAnything::Storage::Frontend::HTTP; | ||||||||||||
| 5 | # git description: v0.011-5-g99b1f16 | ||||||||||||
| 6 | |||||||||||||
| 7 | 3 | our $AUTHORITY = 'cpan:SCHWIGON'; | |||||||||||
| 8 | # ABSTRACT: Access a BenchmarkAnything store via HTTP | ||||||||||||
| 9 | 3 | $BenchmarkAnything::Storage::Frontend::HTTP::VERSION = '0.012'; | |||||||||||
| 10 | 3 | ▶ | use Mojo::Base 'Mojolicious'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 3 | require File::HomeDir; # MUST 'require', 'use' conflicts with Mojolicious | |||||||||||
| 13 | |||||||||||||
| 14 | has bacfg => sub | ||||||||||||
| 15 | 2 | ▶ | { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 2 | require BenchmarkAnything::Config; | |||||||||||
| 17 | 2 | return BenchmarkAnything::Config->new; | |||||||||||
| 18 | 3 | }; | |||||||||||
| 19 | |||||||||||||
| 20 | has balib => sub | ||||||||||||
| 21 | 2 | ▶ | { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 2 | my $self = shift; | |||||||||||
| 23 | |||||||||||||
| 24 | 2 | require BenchmarkAnything::Storage::Frontend::Lib; | |||||||||||
| 25 | 2 | my $balib = BenchmarkAnything::Storage::Frontend::Lib->new(cfgfile => $self->app->bacfg->{cfgfile}); | |||||||||||
| 26 | 2 | $self->log->debug(" - balib.cfgfile: ".$balib->{cfgfile}); | |||||||||||
| 27 | 2 | return $balib; | |||||||||||
| 28 | 3 | }; | |||||||||||
| 29 | |||||||||||||
| 30 | has backend => sub | ||||||||||||
| 31 | 2 | ▶ | { | ||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.5
| |||||||||||||
| 32 | 2 | my $self = shift; | |||||||||||
| 33 | |||||||||||||
| 34 | 2 | require BenchmarkAnything::Storage::Backend::SQL; | |||||||||||
| 35 | 2 | my $bacfg = $self->app->bacfg; | |||||||||||
| 36 | |||||||||||||
| 37 | 2 | ▶ | my $searchengine = $bacfg->{benchmarkanything}{searchengine} || {}; | ||||||||||
|
Condition50%1/2
$bacfg->{'benchmarkanything'}{'searchengine'} || {}
MC/DC0%0/1
$bacfg->{'benchmarkanything'}{'searchengine'} || {}
$bacfg->{'benchmarkanything'}{'searchengine'}
Truth table50%1/2
A
A= $bacfg->{'benchmarkanything'}{'searchengine'}
| |||||||||||||
| 38 | 2 | ▶ | my $dbh_config = $bacfg->{benchmarkanything}{storage}{backend}{sql} || {}; | ||||||||||
|
Condition50%1/2
$bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'} || {}
MC/DC0%0/1
$bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'} || {}
$bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}
Truth table50%1/2
A
A= $bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}
| |||||||||||||
| 39 | |||||||||||||
| 40 | return BenchmarkAnything::Storage::Backend::SQL->new ({ dbh => $self->app->balib->{dbh}, | ||||||||||||
| 41 | dbh_config => $dbh_config, | ||||||||||||
| 42 | debug => $bacfg->{benchmarkanything}{debug}, | ||||||||||||
| 43 | force => $bacfg->{benchmarkanything}{force}, | ||||||||||||
| 44 | verbose => $bacfg->{benchmarkanything}{verbose}, | ||||||||||||
| 45 | 2 | ▶ | (keys %$searchengine ? (searchengine => $searchengine) : ()), | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | }); | ||||||||||||
| 47 | 3 | }; | |||||||||||
| 48 | |||||||||||||
| 49 | |||||||||||||
| 50 | |||||||||||||
| 51 | # This method will run once at server start. | ||||||||||||
| 52 | # | ||||||||||||
| 53 | # IMPORTANT: | ||||||||||||
| 54 | # ---------- | ||||||||||||
| 55 | # YOU MUST NOT CALL ->balib() INSIDE startup()! | ||||||||||||
| 56 | # THAT WOULD INSTANTIATE THE SAME DB CONNECTION FOR MULTIPLE | ||||||||||||
| 57 | # PREFORKED PROCESSES AND THEREFORE MIX UP TRANSACTIONS. | ||||||||||||
| 58 | 2 | ▶ | sub startup { | ||||||||||
|
Subroutine
startup: called CC=8 SCAR=22.4
Pod
documented
| |||||||||||||
| 59 | 2 | my $self = shift; | |||||||||||
| 60 | |||||||||||||
| 61 | 2 | $self->log->debug("Using BenchmarkAnything"); | |||||||||||
| 62 | 2 | $self->log->debug(" - Configfile: ".$self->app->bacfg->{cfgfile}); | |||||||||||
| 63 | 2 | $self->log->debug(" - Backend: ".$self->app->bacfg->{benchmarkanything}{backend}); | |||||||||||
| 64 | 2 | $self->log->debug(" - DSN: ".$self->app->bacfg->{benchmarkanything}{storage}{backend}{sql}{dsn}); | |||||||||||
| 65 | die | ||||||||||||
| 66 | "Config backend:".$self->app->bacfg->{benchmarkanything}{backend}. | ||||||||||||
| 67 | "' not yet supported (".$self->app->bacfg->{cfgfile}. | ||||||||||||
| 68 | "), must be 'local'.\n" | ||||||||||||
| 69 | 2 | ▶ | if $self->app->bacfg->{benchmarkanything}{backend} ne 'local'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | |||||||||||||
| 71 | 2 | ▶ | my $queueing_processing_batch_size = $self->app->bacfg->{benchmarkanything}{storage}{backend}{sql}{queueing}{processing_batch_size} || 100; | ||||||||||
|
Condition50%1/2
$self->app->bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}{'queueing'}{'processing_batch_size'} || 100
MC/DC0%0/1
$self->app->bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}{'queueing'}{'processing_batch_size'} || 100
$self->app->bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}{'queueing'}{'processing_batch_size'}
Truth table50%1/2
A
A= $self->app->bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}{'queueing'}{'processing_batch_size'}
| |||||||||||||
| 72 | 2 | ▶ | my $queueing_processing_sleep = $self->app->bacfg->{benchmarkanything}{storage}{backend}{sql}{queueing}{processing_sleep} || 30; | ||||||||||
|
Condition50%1/2
$self->app->bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}{'queueing'}{'processing_sleep'} || 30
MC/DC0%0/1
$self->app->bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}{'queueing'}{'processing_sleep'} || 30
$self->app->bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}{'queueing'}{'processing_sleep'}
Truth table50%1/2
A
A= $self->app->bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}{'queueing'}{'processing_sleep'}
| |||||||||||||
| 73 | 2 | ▶ | my $queueing_gc_sleep = $self->app->bacfg->{benchmarkanything}{storage}{backend}{sql}{queueing}{gc_sleep} || 120; | ||||||||||
|
Condition50%1/2
$self->app->bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}{'queueing'}{'gc_sleep'} || 120
MC/DC0%0/1
$self->app->bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}{'queueing'}{'gc_sleep'} || 120
$self->app->bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}{'queueing'}{'gc_sleep'}
Truth table50%1/2
A
A= $self->app->bacfg->{'benchmarkanything'}{'storage'}{'backend'}{'sql'}{'queueing'}{'gc_sleep'}
| |||||||||||||
| 74 | |||||||||||||
| 75 | 2 | ▶ | my $disable_process_benchmarkanything_queue = $self->app->bacfg->{benchmarkanything}{storage}{frontend}{http}{disable_process_benchmarkanything_queue} || 0; | ||||||||||
|
Condition50%1/2
$self->app->bacfg->{'benchmarkanything'}{'storage'}{'frontend'}{'http'}{'disable_process_benchmarkanything_queue'} || 0
MC/DC0%0/1
$self->app->bacfg->{'benchmarkanything'}{'storage'}{'frontend'}{'http'}{'disable_process_benchmarkanything_queue'} || 0
$self->app->bacfg->{'benchmarkanything'}{'storage'}{'frontend'}{'http'}{'disable_process_benchmarkanything_queue'}
Truth table50%1/2
A
A= $self->app->bacfg->{'benchmarkanything'}{'storage'}{'frontend'}{'http'}{'disable_process_benchmarkanything_queue'}
| |||||||||||||
| 76 | |||||||||||||
| 77 | 2 | $self->log->debug(" - Q.batch_size: $queueing_processing_batch_size"); | |||||||||||
| 78 | 2 | $self->log->debug(" - Q.sleep: $queueing_processing_sleep"); | |||||||||||
| 79 | 2 | $self->log->debug(" - Q.gc_sleep: $queueing_gc_sleep"); | |||||||||||
| 80 | 2 | $self->log->debug(" - Q.disable_processing: $disable_process_benchmarkanything_queue"); | |||||||||||
| 81 | |||||||||||||
| 82 | 2 | $self->plugin('InstallablePaths'); | |||||||||||
| 83 | |||||||||||||
| 84 | # recurring worker | ||||||||||||
| 85 | 0 | ▶ | Mojo::IOLoop->recurring($queueing_processing_sleep => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 86 | 0 | sleep(rand($queueing_processing_sleep)); | |||||||||||
| 87 | 0 | $self->log->debug("process bench queue (batchsize: $queueing_processing_batch_size) [".~~localtime."]"); | |||||||||||
| 88 | 0 | $self->app->balib->process_raw_result_queue($queueing_processing_batch_size); | |||||||||||
| 89 | 2 | ▶ | }) unless $disable_process_benchmarkanything_queue; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 90 | 0 | ▶ | Mojo::IOLoop->recurring($queueing_gc_sleep => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 91 | 0 | $self->log->debug("garbage collection [".~~localtime."]"); | |||||||||||
| 92 | 0 | $self->app->balib->gc(); | |||||||||||
| 93 | 2 | ▶ | }) unless $disable_process_benchmarkanything_queue; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 94 | |||||||||||||
| 95 | # routes | ||||||||||||
| 96 | 2 | my $routes = $self->routes; | |||||||||||
| 97 | 2 | $routes | |||||||||||
| 98 | ->any('/api/v1/search/:value_id' => [value_id => qr/\d+/]) | ||||||||||||
| 99 | ->to('search#search', value_id => 0); | ||||||||||||
| 100 | 2 | $routes | |||||||||||
| 101 | ->any('/api/v1/listnames/:pattern' => [pattern => qr/[^\/]+/]) | ||||||||||||
| 102 | ->to('search#listnames', pattern => ''); | ||||||||||||
| 103 | 2 | $routes | |||||||||||
| 104 | ->any('/api/v1/listkeys/:pattern' => [pattern => qr/[^\/]+/]) | ||||||||||||
| 105 | ->to('search#listkeys', pattern => ''); | ||||||||||||
| 106 | 2 | $routes | |||||||||||
| 107 | ->any('/api/v1/hello') | ||||||||||||
| 108 | ->to('search#hello'); | ||||||||||||
| 109 | 2 | $routes | |||||||||||
| 110 | ->any('/api/v1/add') | ||||||||||||
| 111 | ->to('submit#add'); | ||||||||||||
| 112 | 2 | $routes | |||||||||||
| 113 | ->any('/api/v1/stats') | ||||||||||||
| 114 | ->to('search#stats'); | ||||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | 3 | 1; | |||||||||||
| 118 | |||||||||||||
| 119 | __END__ | ||||||||||||