Queue/MongoDriver.pm

filter: Statementstmt 54.2% 32 / 59 Branchbran 16.6% 4 / 24 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 60.0% 9 / 15 Podpod 0.0% 0 / 9 totaltotal 40.1% 47 / 117 CC 15 SCAR 19.5
CC
15
Cov
43%
getJobsCron
20.0
__format
12.0
__formatClass
12.0
CRAP 7.0
« Queue/Queues.pm ↑ Summary Queue/RabbitDriver.pm »
1 package Eixo::Queue::MongoDriver;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use MongoDB;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Eixo::Base::Clase;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Eixo::Queue::Job;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 has(
9  
10 db=>undef,
11  
12 collection=>undef,
13  
14 host=>'localhost',
15  
16 port=>27017,
17  
18 __connection=>undef,
19 );
20  
21 2 ▶sub addJob{
Subroutine addJob: called CC=2 SCAR=7.4
Pod undocumented
22 2 my ($self, $job, $collection) = @_;
23  
24 2 ▶ unless($job->isa('Eixo::Queue::Job')){
Branch: 1 branch
BranchTrueFalseTotal
unless ($job->isa("Eixo::Queue::Job")) 0 2 2
25
26 0 die(ref($self) . '::addJob: an Eixo::Queue::Job was expected');
27  
28 }
29  
30 $self->getCollection($collection)->insert_one({
31 _id => $job->id,
32 2 %{$job->to_hash}
33 });
34  
35 }
36  
37 0 ▶sub updateJob{
Subroutine updateJob: not called CC=1 SCAR=6.9
Pod undocumented
38 0 my ($self, $job, $collection) = @_;
39  
40 0 $self->getCollection($collection)->update(
41  
42 {_id=>$job->id} ,
43  
44 $job->to_hash
45 );
46 }
47  
48 0 ▶sub getJob{
Subroutine getJob: not called CC=2 SCAR=17.9
Pod undocumented
49 0 my ($self, $id, $collection, $class) = @_;
50  
51 0 ▶ my $method = ($class) ? "__formatClass" : "__format";
Branch: 1 branch
BranchTrueFalseTotal
$class ? : 0 0 0
52  
53 0 $self->$method(
54  
55 [
56 $self->getCollection($collection)->find({
57
58 _id=>$id
59  
60 })->next
61 ],
62  
63 $class
64  
65 );
66 }
67  
68 0 ▶sub find{
Subroutine find: not called CC=2 SCAR=17.9
Pod undocumented
69 0 my ($self, $query, $sort, $collection, $class) = @_;
70  
71 0 ▶ my $method = ($class) ? "__formatClass" : "__format";
Branch: 1 branch
BranchTrueFalseTotal
$class ? : 0 0 0
72  
73 0 $self->$method(
74  
75 [
76 $self->getCollection($collection)
77
78 ->find($query)
79
80 ->sort($sort)
81  
82 ->all
83 ],
84  
85 $class
86 );
87 }
88  
89 2 ▶sub getPendingJob{
Subroutine getPendingJob: called CC=2 SCAR=7.0
Pod undocumented
90 2 my ($self, %args) = @_;
91  
92 2 my $query = {
93  
94 status=>"WAITING"
95 };
96  
97 2 ▶ $query->{queue} = $args{queue} if(defined $args{queue});
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"queue"} 0 2 2
98  
99 2 $self->__format(
100  
101 [
102 $self->getCollection->find_and_modify({
103  
104 query =>$query,
105 sort => {creation_timestamp => 1},
106 update => {
107 '$set' => {
108 status => 'PROCESSING',
109 start_timestamp => time
110 }
111 },
112 new => 1,
113 })
114  
115 ]
116 );
117  
118 }
119  
120 0 ▶sub getJobsCron{
Subroutine getJobsCron: not called CC=4 SCAR=30.0
Pod undocumented
121 0 my ($self, %args) = @_;
122  
123 0 my $query = {
124  
125 status => "ACTIVE",
126  
127 cron=>1
128
129 };
130  
131 0 ▶ $query->{queue} = $args{queue} if(defined( $args{queue}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"queue"} 0 0 0
132  
133 my @jobs = $self->getCollection(
134 $args{collection_cron}
135 )
136  
137 0 ->find($query)
138  
139 ->all;
140
141 @jobs = map {
142  
143 0 $args{class}->new(%$_)
144  
145 0 } grep {ref($_) } @jobs;
146  
147 0 ▶ wantarray ? @jobs : (@jobs < 2) ? $jobs[0] : \@jobs;
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
@jobs < 2 ? : 0 0 0
148 }
149  
150 0 ▶sub __format{
Subroutine __format: not called CC=3 SCAR=24.8
151 0 my ($self, $jobs) = @_;
152  
153 my @jobs = map {
154  
155 0 Eixo::Queue::Job->new(%$_);
156  
157 0 } grep { ref($_) } @$jobs;
158  
159 0 ▶ wantarray ? @jobs : (@jobs < 2) ? $jobs[0] : \@jobs;
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
@jobs < 2 ? : 0 0 0
160 }
161  
162 0 ▶sub __formatClass{
Subroutine __formatClass: not called CC=3 SCAR=24.8
163 0 my ($self, $jobs, $class) = @_;
164  
165 my @jobs = map {
166  
167 0 $class->new(%$_);
168  
169 0 } grep { ref($_) } @$jobs;
170  
171 0 ▶ wantarray ? @jobs : (@jobs < 2) ? $jobs[0] : \@jobs;
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
@jobs < 2 ? : 0 0 0
172 }
173  
174  
175 4 ▶sub getCollection{
Subroutine getCollection: called CC=2 SCAR=7.6
Pod undocumented
176 4 my ($self, $collection) = @_;
177  
178 4 ▶ $collection = $collection || $self->collection;
Condition33%1/3
$collection || $self->collection
l!l&&r!l&&!r
040
MC/DC0%0/2
$collection || $self->collection
$collection $self->collection
Truth table33%1/3
A || B
A= $collectionB= $self->collection
ABresult
1X1
011
000
179  
180 4 $self->getDb->get_collection($collection);
181  
182 }
183  
184 6 ▶sub getDb{
Subroutine getDb: called CC=2 SCAR=7.6
Pod undocumented
185 6 my ($self, $db) = @_;
186  
187 6 ▶ $db = $db || $self->db;
Condition33%1/3
$db || $self->db
l!l&&r!l&&!r
060
MC/DC0%0/2
$db || $self->db
$db $self->db
Truth table33%1/3
A || B
A= $dbB= $self->db
ABresult
1X1
011
000
188  
189 6 $self->getConnection->get_database($db);
190
191  
192 }
193  
194 6 ▶sub getConnection{
Subroutine getConnection: called CC=2 SCAR=6.9
Pod undocumented
195  
196 6 ▶ return $_[0]->__connection if($_[0]->__connection);
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->__connection 1 5 6
197  
198 5 my $c;
199  
200 5 $_[0]->__connection(
201  
202  
203 $c = MongoDB::MongoClient->new(
204  
205 host=>$_[0]->host,
206  
207 port=>$_[0]->port
208  
209 )
210  
211 );
212  
213 5 $_[0]->__connection;
214 }
215  
216 #__PACKAGE__->new->getConexion;
217  
218 2 1;
« Queue/Queues.pm ↑ Summary Queue/RabbitDriver.pm »