Overview.pm

filter: Statementstmt 25.3% 17 / 67 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 55.5% 5 / 9 Podpod 100% 1 / 1 totaltotal 25.2% 23 / 91 CC 6 SCAR 21.9
CC
6
Cov
22%
__ANON__
20.0
register
12.0
__ANON__
2.0
CRAP 8.9
« Overview/Backend.pm ↑ Summary Overview/Controller/Jobs.pm »
1 package Mojolicious::Plugin::Minion::Overview;
2 2 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 ▶use Mojolicious::Plugin::Minion::Overview::Facade;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Mojo::ByteStream 'b';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Mojo::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Mojo::File 'path';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '0.1.2';
11  
12  
13 =head2 register
14  
15 Register the plugin and defined the routes
16  
17 =cut
18  
19 0 ▶sub register {
Subroutine register: not called CC=3 SCAR=24.8
Pod documented
20 0 my ($self, $app, $config) = @_;
21  
22 # TODO: Find out why the connection is dropped
23 # my $minion_overview = Mojolicious::Plugin::Minion::Overview::Facade->load($app->minion);
24 0 ▶ $app->helper(minion_overview => sub { Mojolicious::Plugin::Minion::Overview::Facade->load($app->minion) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
25  
26 0 ▶ $app->helper(overview_job_status => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
27 0 my ($c, $status) = @_;
28  
29 0 my $html = sprintf('<span class="fa fa-pause-circle text-muted" title="%s"></span>', $status);
30  
31 0 ▶ if ($status eq 'finished') {
Branch: 3 branches
BranchTrueFalseTotal
if ($status eq 'finished') { } 0 0 0
elsif ($status eq 'failed') { } 0 0 0
elsif ($status eq 'active') { } 0 0 0
32 0 $html = sprintf('<span class="fa fa-check-circle text-success" title="%s"></span>', $status);
33 } elsif ($status eq 'failed') {
34 0 $html = sprintf('<span class="fa fa-times-circle text-danger" title="%s"></span>', $status);
35 } elsif ($status eq 'active') {
36 0 $html = sprintf('<span class="fa fa-play-circle text-warning" title="%s"></span>', $status);
37 }
38  
39 0 return b($html);
40 0 });
41  
42 0 ▶ $app->helper(overview_job_date => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 0 my ($c, $timestamp) = @_;
44  
45 0 my $date = Mojo::Date->new($timestamp);
46  
47 0 return $date->to_datetime;
48 0 });
49  
50 0 push(@{ $app->routes->namespaces }, 'Mojolicious::Plugin::Minion::Overview::Controller');
51  
52 # Config
53 0 ▶ my $prefix = $config->{route} // $app->routes->route('minion-overview');
Condition0%0/3
$config->{"route"} // $app->routes->route("minion-overview")
l!l&&r!l&&!r
000
MC/DC0%0/2
$config->{"route"} // $app->routes->route("minion-overview")
$config->{"route"} $app->routes->route("minion-overview")
Truth table0%0/3
A // B
A= $config->{"route"}B= $app->routes->route("minion-overview")
ABresult
1X1
011
000
54 0 ▶ $prefix->to(return_to => $config->{return_to} // '/');
Condition0%0/2
$config->{"return_to"} // "/"
l!l
00
MC/DC0%0/1
$config->{"return_to"} // "/"
$config->{"return_to"}
Truth table0%0/2
A
A= $config->{"return_to"}
Aresult
11
00
55  
56 # Static files
57 0 my $resources = path(__FILE__)->sibling('Overview', 'resources');
58 0 push @{$app->static->paths}, $resources->child('public')->to_string;
59  
60 # Templates
61 0 push @{$app->renderer->paths}, $resources->child('templates')->to_string;
62  
63 # Set date
64 0 $prefix->get('/date/:date')
65 ->to(controller => 'Overview', action => 'setDate')
66 ->name('minion_overview.overview.set_date');
67  
68 # Dashboard
69 0 $prefix->get('/')
70 ->to(controller => 'Dashboard', action => 'search');
71  
72 0 my $dashboard = $prefix->route('dashboard')
73 ->to(controller => 'Dashboard');
74  
75 0 $dashboard->get('/')->to(action => 'search')
76 ->name('minion_overview.dashboard');
77  
78 0 $dashboard->get('overview')->to(action => 'overview')
79 ->name('minion_overview.dashboard.overview');
80  
81 0 $dashboard->get('workers')->to(action => 'workers')
82 ->name('minion_overview.dashboard.workers');
83  
84 # Metrics
85 0 my $metrics = $prefix->route('metrics')
86 ->to(controller => 'Metrics');
87  
88 0 $metrics->get('/')->to(action => 'search')
89 ->name('minion_overview.metrics');
90  
91 0 my $metrics_jobs = $metrics->route('jobs')
92 ->to(controller => 'Metrics::Jobs');
93  
94 0 $metrics_jobs->get(':job')->to(action => 'show')
95 ->name('minion_overview.metrics.jobs.show');
96  
97 0 my $metrics_workers = $metrics->route('workers')
98 ->to(controller => 'Metrics::Workers');
99  
100 0 $metrics_workers->get(':worker')->to(action => 'show')
101 ->name('minion_overview.metrics.workers.show');
102  
103 # Recent Jobs
104 0 my $failed_jobs = $prefix->route('failed-jobs')
105 ->to(controller => 'FailedJobs');
106  
107 0 $failed_jobs->get('/')->to(action => 'search')
108 ->name('minion_overview.failed_jobs');
109  
110 # Jobs
111 0 my $jobs = $prefix->route('jobs')
112 ->to(controller => 'Jobs');
113  
114 0 $jobs->get('/')->to(action => 'search')
115 ->name('minion_overview.jobs');
116  
117 0 $jobs->get('/:id')->to(action => 'show')
118 ->name('minion_overview.jobs.show');
119  
120 0 $jobs->get('/:id/retry')->to(action => 'retry')
121 ->name('minion_overview.jobs.retry');
122  
123  
124 # API
125 0 my $api = $prefix->route('api');
126  
127 # Metrics
128 0 my $api_metrics = $api->route('metrics');
129  
130 # Jobs
131 0 my $api_metrics_jobs = $api_metrics->route('jobs')
132 ->to(controller => 'API::Metrics::Jobs');
133  
134 0 $api_metrics_jobs->get('/:job/runtime')->to(action => 'runtime')
135 ->name('minion_overview.api.metrics.jobs.runtime');
136  
137 0 $api_metrics_jobs->get('/:job/throughput')->to(action => 'throughput')
138 ->name('minion_overview.api.metrics.jobs.throughput');
139  
140 # Workers
141 0 my $api_metrics_workers = $api_metrics->route('workers')
142 ->to(controller => 'API::Metrics::Workers');
143  
144 0 $api_metrics_workers->get('/:worker/waittime')->to(action => 'waittime')
145 ->name('minion_overview.api.metrics.workers.waittime');
146  
147 0 $api_metrics_workers->get('/:worker/throughput')->to(action => 'throughput')
148 ->name('minion_overview.api.metrics.workers.throughput');
149 }
150  
151 2 1;
« Overview/Backend.pm ↑ Summary Overview/Controller/Jobs.pm »