| 1 | package Mojolicious::Plugin::Minion::Overview::Backend; | ||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Minion; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||
| 6 | 2 | has 'db'; | |||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||
| 8 | 0 | ▶ | has 'minion' => sub { Minion->new }, weak => 1; | ||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||
| 10 | 0 | ▶ | has 'query' => sub {{ | ||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||
| 11 | 0 | limit => 25, | |||||||||||||||||||||||||
| 12 | page => 1, | ||||||||||||||||||||||||||
| 13 | where => {}, | ||||||||||||||||||||||||||
| 14 | tags => [], | ||||||||||||||||||||||||||
| 15 | term => '', | ||||||||||||||||||||||||||
| 16 | 2 | }}; | |||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||
| 18 | 2 | has 'start' => 'CURDATE()'; | |||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||
| 21 | =head2 clear_query | ||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||
| 23 | Clear the query fields | ||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub clear_query { | ||||||||||||||||||||||||
|
Subroutine
clear_query: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 28 | 0 | my $self = shift; | |||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||
| 30 | 0 | $self->query({ | |||||||||||||||||||||||||
| 31 | limit => 25, | ||||||||||||||||||||||||||
| 32 | page => 1, | ||||||||||||||||||||||||||
| 33 | where => {}, | ||||||||||||||||||||||||||
| 34 | tags => [], | ||||||||||||||||||||||||||
| 35 | term => '', | ||||||||||||||||||||||||||
| 36 | }); | ||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||
| 38 | 0 | return $self; | |||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||
| 41 | =head2 date | ||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||
| 43 | Set date | ||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub date { | ||||||||||||||||||||||||
|
Subroutine
date: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||
| 48 | 0 | my ($self, $date) = @_; | |||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||
| 50 | 0 | my $start = 'CURDATE()'; | |||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($date eq 'Since yesterday') { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 53 | 0 | $start = 'DATE_ADD(CURDATE(), INTERVAL -1 DAY)'; | |||||||||||||||||||||||||
| 54 | } elsif ($date eq 'Last 3 days') { | ||||||||||||||||||||||||||
| 55 | 0 | $start = 'DATE_ADD(CURDATE(), INTERVAL -3 DAY)'; | |||||||||||||||||||||||||
| 56 | } elsif ($date eq 'Last 7 days') { | ||||||||||||||||||||||||||
| 57 | 0 | $start = 'DATE_ADD(CURDATE(), INTERVAL -7 DAY)'; | |||||||||||||||||||||||||
| 58 | } elsif ($date eq 'This month') { | ||||||||||||||||||||||||||
| 59 | 0 | $start = 'LAST_DAY(CURDATE() + INTERVAL -1 MONTH) + INTERVAL 1 DAY'; | |||||||||||||||||||||||||
| 60 | } elsif ($date eq 'Last 3 months') { | ||||||||||||||||||||||||||
| 61 | 0 | $start = 'LAST_DAY(CURDATE() + INTERVAL -3 MONTH) + INTERVAL 1 DAY'; | |||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||
| 64 | 0 | $self->start($start); | |||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||
| 66 | 0 | return $self; | |||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||
| 69 | =head2 dashboard | ||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||
| 71 | Dashboard stats | ||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub dashboard { | ||||||||||||||||||||||||
|
Subroutine
dashboard: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 76 | 0 | my $self = shift; | |||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||
| 78 | return { | ||||||||||||||||||||||||||
| 79 | 0 | overview => $self->overview, | |||||||||||||||||||||||||
| 80 | workers => $self->workers, | ||||||||||||||||||||||||||
| 81 | }; | ||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||
| 84 | =head2 failed_jobs | ||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||
| 86 | Search failed jobs | ||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub failed_jobs { | ||||||||||||||||||||||||
|
Subroutine
failed_jobs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 91 | 0 | return {}; | |||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||
| 94 | =head2 job | ||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||
| 96 | Find a job by id | ||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub job { | ||||||||||||||||||||||||
|
Subroutine
job: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 101 | 0 | my ($self, $id) = @_; | |||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||
| 103 | 0 | return $self->minion->job($id); | |||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||
| 106 | =head2 job_runtime_metrics | ||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||
| 108 | Job runtime metrics | ||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub job_runtime_metrics { | ||||||||||||||||||||||||
|
Subroutine
job_runtime_metrics: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 113 | 0 | return []; | |||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||
| 116 | =head2 job_throughput_metrics | ||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||
| 118 | Job throughput metrics | ||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||
| 120 | =cut | ||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub job_throughput_metrics { | ||||||||||||||||||||||||
|
Subroutine
job_throughput_metrics: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 123 | 0 | return []; | |||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||
| 126 | =head2 jobs | ||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||
| 128 | Search jobs | ||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||
| 130 | =cut | ||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub jobs { | ||||||||||||||||||||||||
|
Subroutine
jobs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 133 | 0 | return {}; | |||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||
| 136 | =head2 limit | ||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||
| 138 | Set the limit and return current instance | ||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||
| 140 | =cut | ||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub limit { | ||||||||||||||||||||||||
|
Subroutine
limit: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 143 | 0 | my ($self, $limit) = @_; | |||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||
| 145 | 0 | $self->query->{ limit } = $limit; | |||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||
| 147 | 0 | return $self; | |||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||
| 150 | =head2 overview | ||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||
| 152 | Dashboard overview | ||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub overview { | ||||||||||||||||||||||||
|
Subroutine
overview: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 157 | 0 | return []; | |||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||
| 160 | =head2 page | ||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||
| 162 | Set the page and return current instance | ||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||
| 164 | =cut | ||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub page { | ||||||||||||||||||||||||
|
Subroutine
page: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 167 | 0 | my ($self, $page) = @_; | |||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||
| 169 | 0 | $self->query->{ page } = $page; | |||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||
| 171 | 0 | return $self; | |||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||
| 174 | =head2 search | ||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||
| 176 | Set the search term and return current instance | ||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||
| 178 | =cut | ||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||
| 180 | 0 | ▶ | sub search { | ||||||||||||||||||||||||
|
Subroutine
search: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 181 | 0 | my ($self, $term) = @_; | |||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||
| 183 | 0 | $self->query->{ term } = $term; | |||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||
| 185 | 0 | return $self; | |||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||
| 188 | =head2 tags | ||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||
| 190 | Set the search tags and return current instance | ||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||
| 192 | =cut | ||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||
| 194 | 0 | ▶ | sub tags { | ||||||||||||||||||||||||
|
Subroutine
tags: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 195 | 0 | my ($self, $tags) = @_; | |||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||
| 197 | 0 | push(@{ $self->query->{ tags } }, @$tags); | |||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||
| 199 | 0 | return $self; | |||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||
| 202 | =head2 unique_jobs | ||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||
| 204 | Search the list of unique jobs | ||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||
| 206 | =cut | ||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||
| 208 | 0 | ▶ | sub unique_jobs { | ||||||||||||||||||||||||
|
Subroutine
unique_jobs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 209 | 0 | return {}; | |||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||
| 212 | =head2 when | ||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||
| 214 | Add where condition when first param is true | ||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||
| 216 | =cut | ||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||
| 218 | 0 | ▶ | sub when { | ||||||||||||||||||||||||
|
Subroutine
when: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||
| 219 | 0 | my ($self, $value, $field) = @_; | |||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||
| 221 | 0 | ▶ | if ($value) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 222 | 0 | $self->where($field, $value); | |||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||
| 225 | 0 | return $self; | |||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||
| 228 | =head2 where | ||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||
| 230 | Add a condition for a field and return current instance | ||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||
| 232 | =cut | ||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||
| 234 | 0 | ▶ | sub where { | ||||||||||||||||||||||||
|
Subroutine
where: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||
| 235 | 0 | my $self = shift; | |||||||||||||||||||||||||
| 236 | 0 | my $field = shift; | |||||||||||||||||||||||||
| 237 | 0 | my $condition = shift; | |||||||||||||||||||||||||
| 238 | 0 | my $value = shift; | |||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||
| 240 | 0 | ▶ | $self->query->{ where }->{ $field } = $value || $condition; | ||||||||||||||||||||||||
|
Condition0%0/3
$value || $condition
MC/DC0%0/2
$value || $condition
$value
$condition
Truth table0%0/3
A || B
A= $valueB= $condition
| |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||
| 242 | 0 | return $self; | |||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||
| 245 | =head2 worker | ||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||
| 247 | Find a worker by id | ||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||
| 249 | =cut | ||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub worker { | ||||||||||||||||||||||||
|
Subroutine
worker: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 252 | 0 | return {}; | |||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||
| 255 | =head2 worker_waittime_metrics | ||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||
| 257 | Worker waittime metrics | ||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||
| 259 | =cut | ||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||
| 261 | 0 | ▶ | sub worker_waittime_metrics { | ||||||||||||||||||||||||
|
Subroutine
worker_waittime_metrics: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 262 | 0 | return []; | |||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||
| 265 | =head2 worker_throughput_metrics | ||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||
| 267 | Worker throughput metrics | ||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||
| 269 | =cut | ||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||
| 271 | 0 | ▶ | sub worker_throughput_metrics { | ||||||||||||||||||||||||
|
Subroutine
worker_throughput_metrics: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 272 | 0 | return []; | |||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||
| 275 | =head2 workers | ||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||
| 277 | Get workers information | ||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||
| 279 | =cut | ||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||
| 281 | 0 | ▶ | sub workers { | ||||||||||||||||||||||||
|
Subroutine
workers: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 282 | 0 | return []; | |||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||
| 285 | 2 | 1; | |||||||||||||||||||||||||