Minion/Iterator.pm

filter: Statementstmt 23.0% 6 / 26 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 20.0% 1 / 5 Podpod 100% 3 / 3 totaltotal 17.5% 10 / 57 CC 9 SCAR 38.2
CC
9
Cov
14%
_fetch
72.0
each
6.0
next
2.0
CRAP 45.6
« Mojolicious/Plugin/Minion/Admin.pm ↑ Summary Minion.pm »
1 package Minion::Iterator;
2 2 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 has fetch => 10;
5 2 has [qw(minion options)];
6  
7 0 ▶sub each {
Subroutine each: not called CC=2 SCAR=17.9
Pod documented
8 0 my ($self, $cb) = @_;
9 0 ▶ while ($_ = $self->next) { $cb->($_) }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = $self->next) 0 0 0
10 }
11  
12 0 ▶sub next { shift @{shift->_fetch(0)->{results}} }
Subroutine next: not called CC=1 SCAR=6.9
Pod documented
13  
14 0 ▶sub total { shift->_fetch(1)->{total} }
Subroutine total: not called CC=1 SCAR=6.9
Pod documented
15  
16 0 ▶sub _fetch {
Subroutine _fetch: not called CC=8 SCAR=42.8
17 0 my ($self, $lazy) = @_;
18  
19 0 ▶ return $self if ($lazy && exists $self->{total}) || @{$self->{results} // []};
Branch: 1 branch
BranchTrueFalseTotal
if $lazy and exists $self->{"total"} or @{$self->{"results"} // [];} 0 0 0
Condition0%0/8
$lazy and exists $self->{"total"} or @{$self->{"results"} // [];}
l!l&&r!l&&!r
000
$lazy and exists $self->{"total"}
!ll&&!rl&&r
000
$self->{"results"} // []
l!l
00
MC/DC0%0/3
$lazy and exists $self->{"total"} or @{$self->{"results"} // [];}
$lazy exists $self->{"total"} @{$self->{"results"} // [];}
MC/DC0%0/1
$self->{"results"} // []
$self->{"results"}
Truth table0%0/5
A and B or C
A= $lazyB= exists $self->{"total"}C= @{$self->{"results"} // [];}
ABCresult
11X1
0X11
1011
0X00
1000
Truth table0%0/2
A
A= $self->{"results"}
Aresult
11
00
20  
21 0 ▶ my $what = $self->{jobs} ? 'jobs' : 'workers';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'jobs'} ? : 0 0 0
22 0 my $method = "list_$what";
23 0 my $options = $self->options;
24 0 my $results = $self->minion->backend->$method(0, $self->fetch, $options);
25  
26 0 ▶ $self->{total} = $results->{total} + ($self->{count} // 0);
Condition0%0/2
$self->{"count"} // 0
l!l
00
MC/DC0%0/1
$self->{"count"} // 0
$self->{"count"}
Truth table0%0/2
A
A= $self->{"count"}
Aresult
11
00
27 0 $self->{count} += my @results = @{$results->{$what}};
28 0 push @{$self->{results}}, @results;
29 0 ▶ $options->{before} = $results[-1]{id} if @results;
Branch: 1 branch
BranchTrueFalseTotal
if @results 0 0 0
30  
31 0 return $self;
32 }
33  
34 2 1;
35  
36 =encoding utf8
37  
38 =head1 NAME
39  
40 Minion::Iterator - Minion iterator
41  
42 =head1 SYNOPSIS
43  
44 use Minion::Iterator;
45  
46 my $iter = Minion::Iterator->new(minion => $minion, options => {states => ['inactive']});
47  
48 =head1 DESCRIPTION
49  
50 L<Minion::Iterator> is an iterator for L<Minion> listing methods.
51  
52 =head1 ATTRIBUTES
53  
54 L<Minion::Iterator> implements the following attributes.
55  
56 =head2 fetch
57  
58 my $fetch = $iter->fetch;
59 $iter = $iter->fetch(2);
60  
61 Number of results to cache, defaults to C<10>.
62  
63 =head2 minion
64  
65 my $minion = $iter->minion;
66 $iter = $iter->minion(Minion->new);
67  
68 L<Minion> object this job belongs to.
69  
70 =head2 options
71  
72 my $options = $iter->options;
73 $iter = $iter->options({states => ['inactive']});
74  
75 Options to be passed to L<Minion::Backend/"list_jobs"> or L<Minion::Backend/"list_workers">.
76  
77 =head1 METHODS
78  
79 L<Minion::Iterator> inherits all methods from L<Mojo::Base> and implements the following new ones.
80  
81 =head2 each
82  
83 $iter->each(sub {...});
84  
85 Evaluate callback for each element in collection. The element will be the first argument passed to the callback, and is
86 also available as C<$_>.
87  
88 =head2 next
89  
90 my $value = $iter->next;
91  
92 Get next value.
93  
94 =head2 total
95  
96 my $num = $iter->total;
97  
98 Total number of results. If results are removed in the backend while iterating, this number will become an estimate
99 that gets updated every time new results are fetched.
100  
101 =head1 SEE ALSO
102  
103 L<Minion>, L<Minion::Guide>, L<https://minion.pm>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
104  
105 =cut
« Mojolicious/Plugin/Minion/Admin.pm ↑ Summary Minion.pm »