line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Minion::Overview::Backend; |
2
|
1
|
|
|
1
|
|
519
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
648
|
use Minion; |
|
1
|
|
|
|
|
169676
|
|
|
1
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has 'db'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'minion' => sub { Minion->new }, weak => 1; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'query' => sub {{ |
11
|
|
|
|
|
|
|
limit => 25, |
12
|
|
|
|
|
|
|
page => 1, |
13
|
|
|
|
|
|
|
where => {}, |
14
|
|
|
|
|
|
|
tags => [], |
15
|
|
|
|
|
|
|
term => '', |
16
|
|
|
|
|
|
|
}}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'start' => 'CURDATE()'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head2 clear_query |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Clear the query fields |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub clear_query { |
28
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub date { |
48
|
0
|
|
|
0
|
1
|
|
my ($self, $date) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $start = 'CURDATE()'; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if ($date eq 'Since yesterday') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub dashboard { |
76
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return { |
79
|
0
|
|
|
|
|
|
overview => $self->overview, |
80
|
|
|
|
|
|
|
workers => $self->workers, |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 job |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Find a job by id |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub job { |
91
|
0
|
|
|
0
|
1
|
|
my ($self, $id) = @_; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return $self->minion->job($id); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 limit |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Set the limit and return current instance |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub limit { |
103
|
0
|
|
|
0
|
1
|
|
my ($self, $limit) = @_; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$self->query->{ limit } = $limit; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return $self; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 overview |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Dashboard overview |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub overview { |
117
|
0
|
|
|
0
|
1
|
|
return []; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 page |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Set the page and return current instance |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub page { |
127
|
0
|
|
|
0
|
1
|
|
my ($self, $page) = @_; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
$self->query->{ page } = $page; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
return $self; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 search |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Set the search term and return current instance |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub search { |
141
|
0
|
|
|
0
|
1
|
|
my ($self, $term) = @_; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
$self->query->{ term } = $term; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
return $self; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 tags |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Set the search tags and return current instance |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub tags { |
155
|
0
|
|
|
0
|
1
|
|
my ($self, $tags) = @_; |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
push(@{ $self->query->{ tags } }, @$tags); |
|
0
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
return $self; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 when |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Add where condition when first param is true |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub when { |
169
|
0
|
|
|
0
|
1
|
|
my ($self, $value, $field) = @_; |
170
|
|
|
|
|
|
|
|
171
|
0
|
0
|
|
|
|
|
if ($value) { |
172
|
0
|
|
|
|
|
|
$self->where($field, $value); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
return $self; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 where |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Add a condition for a field and return current instance |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub where { |
185
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
186
|
0
|
|
|
|
|
|
my $field = shift; |
187
|
0
|
|
|
|
|
|
my $condition = shift; |
188
|
0
|
|
|
|
|
|
my $value = shift; |
189
|
|
|
|
|
|
|
|
190
|
0
|
|
0
|
|
|
|
$self->query->{ where }->{ $field } = $value || $condition; |
191
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
return $self; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 workers |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Get workers information |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub workers { |
202
|
0
|
|
|
0
|
1
|
|
return []; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
1; |