| 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 | sub addJob{ | ||||||||||||||||||||
| 22 | 2 | ▶ | my ($self, $job) = @_; | ||||||||||||||||||
|
Subroutine
addJob: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 2 | ▶ | unless($job->isa('Eixo::Queue::Job')){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | die(ref($self) . '::addJob: an Eixo::Queue::Job was expected'); | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | $self->getCollection->insert_one({ | ||||||||||||||||||||
| 31 | _id => $job->id, | ||||||||||||||||||||
| 32 | 2 | %{$job->to_hash} | |||||||||||||||||||
| 33 | }); | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | sub updateJob{ | ||||||||||||||||||||
| 38 | 0 | ▶ | my ($self, $job) = @_; | ||||||||||||||||||
|
Subroutine
updateJob: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | $self->getCollection->update( | |||||||||||||||||||
| 41 | {_id=>$job->id} , | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | $job->to_hash | ||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | sub getJob{ | ||||||||||||||||||||
| 48 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||
|
Subroutine
getJob: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | $self->__format( | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | $self->getCollection->find({ | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | _id=>$id | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | })->next | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | sub find{ | ||||||||||||||||||||
| 62 | 0 | ▶ | my ($self, $query, $sort) = @_; | ||||||||||||||||||
|
Subroutine
find: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | $self->__format( | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | $self->getCollection | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | ->find($query) | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | ->sort($sort) | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | ->all | ||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | sub getPendingJob{ | ||||||||||||||||||||
| 77 | 2 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
getPendingJob: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 2 | my $query = { | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | status=>"WAITING" | ||||||||||||||||||||
| 82 | }; | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 2 | ▶ | $query->{queue} = $args{queue} if(defined $args{queue}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 2 | $self->__format( | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | $self->getCollection->find_and_modify({ | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | query =>$query, | ||||||||||||||||||||
| 91 | sort => {creation_timestamp => 1}, | ||||||||||||||||||||
| 92 | update => { | ||||||||||||||||||||
| 93 | '$set' => { | ||||||||||||||||||||
| 94 | status => 'PROCESSING', | ||||||||||||||||||||
| 95 | start_timestamp => time | ||||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | }, | ||||||||||||||||||||
| 98 | new => 1, | ||||||||||||||||||||
| 99 | }) | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | sub __format{ | ||||||||||||||||||||
| 107 | 0 | ▶ | my ($self, @jobs) = @_; | ||||||||||||||||||
|
Subroutine
__format: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | @jobs = map { | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 0 | Eixo::Queue::Job->new(%$_); | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 0 | } grep { ref($_) } @jobs; | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 0 | ▶ | wantarray ? @jobs : (@jobs < 2) ? $jobs[0] : \@jobs; | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | sub getCollection{ | ||||||||||||||||||||
| 120 | 4 | ▶ | my ($self, $collection) = @_; | ||||||||||||||||||
|
Subroutine
getCollection: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 4 | ▶ | $collection = $collection || $self->collection; | ||||||||||||||||||
|
Condition33%1/3
$collection || $self->collection
MC/DC0%0/2
$collection || $self->collection
$collection
$self->collection
Truth table33%1/3
A || B
A= $collectionB= $self->collection
| |||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 4 | $self->getDb->get_collection($collection); | |||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | } | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | sub getDb{ | ||||||||||||||||||||
| 129 | 6 | ▶ | my ($self, $db) = @_; | ||||||||||||||||||
|
Subroutine
getDb: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 6 | ▶ | $db = $db || $self->db; | ||||||||||||||||||
|
Condition33%1/3
$db || $self->db
MC/DC0%0/2
$db || $self->db
$db
$self->db
Truth table33%1/3
A || B
A= $dbB= $self->db
| |||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 6 | $self->getConnection->get_database($db); | |||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | sub getConnection{ | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 6 | ▶ | return $_[0]->__connection if($_[0]->__connection); | ||||||||||||||||||
|
Subroutine
getConnection: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 5 | my $c; | |||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 5 | $_[0]->__connection( | |||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | $c = MongoDB::MongoClient->new( | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | host=>$_[0]->host, | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | port=>$_[0]->port | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | ) | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | ); | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 5 | $_[0]->__connection; | |||||||||||||||||||
| 158 | } | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | #__PACKAGE__->new->getConexion; | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 2 | 1; | |||||||||||||||||||