blib/lib/App/Netdisco/Web/Health.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod n/a totaltotal 0.0% 0 / 39 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package App::Netdisco::Web::Health;
2  
3 use Dancer ':syntax';
4 use Dancer::Plugin::DBIC;
5  
6 use Try::Tiny;
7  
8 if (my $path = setting('health_path')) {
9 get $path => sub {
10 content_type 'application/json';
11  
12 # Deflater has no minimum size, and gzipping a body this small makes it
13 # bigger. Probes hit this every few seconds.
14 request->env->{'psgix.no-compress'} = 1;
15  
16 my $db_ok = try {
17 schema('netdisco')->storage->dbh->ping;
18 1;
19 } catch { 0 };
20  
21 my @backends = try {
22 schema('netdisco')->resultset('DeviceSkip')
23 ->search({ device => '255.255.255.255' })->hri->all;
24 } catch { () };
25  
26 my $num_backends = scalar @backends;
27 my $tot_workers = 0;
28 $tot_workers += $_->{deferrals} for @backends;
29  
30 my $status = $db_ok ? 'ok' : 'degraded';
31 status( $db_ok ? 200 : 503 );
32  
33 return to_json {
34 status => $status,
35 db => ($db_ok ? 'ok' : 'error'),
36 backends => $num_backends,
37 workers => $tot_workers,
38 };
39 };
40 }
41  
42 true;