|
1
|
|
|
<?php namespace Comodojo\Extender\Queue; |
|
2
|
|
|
|
|
3
|
|
|
use \Comodojo\Foundation\Base\Configuration; |
|
4
|
|
|
use \Comodojo\Foundation\Base\ConfigurationTrait; |
|
5
|
|
|
use \Comodojo\Foundation\Events\Manager as EventsManager; |
|
6
|
|
|
use \Comodojo\Foundation\Logging\LoggerTrait; |
|
7
|
|
|
use \Comodojo\Foundation\Events\EventsTrait; |
|
8
|
|
|
use \Comodojo\Extender\Components\Database; |
|
9
|
|
|
use \Comodojo\Extender\Traits\EntityManagerTrait; |
|
10
|
|
|
use \Comodojo\Extender\Task\Request; |
|
11
|
|
|
use \Comodojo\Extender\Orm\Entities\Queue; |
|
12
|
|
|
use \Comodojo\Extender\Events\QueueEvent; |
|
13
|
|
|
use \Doctrine\ORM\EntityManager; |
|
14
|
|
|
use \Psr\Log\LoggerInterface; |
|
15
|
|
|
use \Exception; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @package Comodojo Extender |
|
19
|
|
|
* @author Marco Giovinazzi <[email protected]> |
|
20
|
|
|
* @license MIT |
|
21
|
|
|
* |
|
22
|
|
|
* LICENSE: |
|
23
|
|
|
* |
|
24
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
25
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
26
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
27
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
28
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
29
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
30
|
|
|
* THE SOFTWARE. |
|
31
|
|
|
*/ |
|
32
|
|
|
|
|
33
|
|
|
class Manager { |
|
34
|
|
|
|
|
35
|
|
|
use ConfigurationTrait; |
|
36
|
|
|
use LoggerTrait; |
|
37
|
|
|
use EventsTrait; |
|
38
|
|
|
use EntityManagerTrait; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Class constructor |
|
42
|
|
|
* |
|
43
|
|
|
* @param Configuration $configuration |
|
44
|
|
|
* @param LoggerInterface $logger |
|
45
|
|
|
* @param TasksTable $tasks |
|
|
|
|
|
|
46
|
|
|
* @param EventsManager $events |
|
47
|
|
|
* @param EntityManager $em |
|
48
|
|
|
*/ |
|
49
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
|
|
50
|
|
|
Configuration $configuration, |
|
51
|
|
|
LoggerInterface $logger, |
|
52
|
|
|
EventsManager $events, |
|
53
|
|
|
EntityManager $em = null |
|
54
|
|
|
) { |
|
55
|
|
|
|
|
56
|
|
|
$this->setConfiguration($configuration); |
|
57
|
|
|
$this->setLogger($logger); |
|
58
|
|
|
$this->setEvents($events); |
|
59
|
|
|
|
|
60
|
|
|
$em = is_null($em) ? Database::init($configuration)->getEntityManager() : $em; |
|
61
|
|
|
$this->setEntityManager($em); |
|
62
|
|
|
|
|
63
|
|
|
// $logger->debug("Tasks Manager online", array( |
|
|
|
|
|
|
64
|
|
|
// 'lagger_timeout' => $this->lagger_timeout, |
|
|
|
|
|
|
65
|
|
|
// 'multithread' => $this->multithread, |
|
|
|
|
|
|
66
|
|
|
// 'max_runtime' => $this->max_runtime, |
|
|
|
|
|
|
67
|
|
|
// 'max_childs' => $this->max_childs |
|
|
|
|
|
|
68
|
|
|
// )); |
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function get() { |
|
73
|
|
|
|
|
74
|
|
|
$em = $this->getEntityManager(); |
|
75
|
|
|
|
|
76
|
|
|
return $em->getRepository('Comodojo\Extender\Orm\Entities\Queue')->findAll(); |
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function flush(array $queue) { |
|
81
|
|
|
|
|
82
|
|
|
$this->getEvents()->emit( new QueueEvent('flush', null, $queue) ); |
|
83
|
|
|
|
|
84
|
|
|
$em = $this->getEntityManager(); |
|
85
|
|
|
|
|
86
|
|
|
foreach ($queue as $record) { |
|
87
|
|
|
$em->remove($record); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$em->flush(); |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function add(Request $request) { |
|
95
|
|
|
|
|
96
|
|
|
$em = $this->getEntityManager(); |
|
97
|
|
|
|
|
98
|
|
|
$uid = $this->doAddRequest($request, $em); |
|
99
|
|
|
|
|
100
|
|
|
$em->flush(); |
|
101
|
|
|
|
|
102
|
|
|
return $uid; |
|
103
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function addBulk(array $queue) { |
|
107
|
|
|
|
|
108
|
|
|
$em = $this->getEntityManager(); |
|
109
|
|
|
|
|
110
|
|
|
$records = []; |
|
111
|
|
|
|
|
112
|
|
|
foreach ($queue as $name => $request) { |
|
113
|
|
|
$records[] = $request instanceof Request ? $this->doAddRequest($request, $em) : false; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$em->flush(); |
|
117
|
|
|
|
|
118
|
|
|
return $records; |
|
119
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
protected function doAddRequest(Request $request, EntityManager $em) { |
|
123
|
|
|
|
|
124
|
|
|
$this->getEvents()->emit( new QueueEvent('add', $request) ); |
|
125
|
|
|
|
|
126
|
|
|
$record = new Queue(); |
|
127
|
|
|
$record->setName($request->getName())->setRequest($request); |
|
128
|
|
|
|
|
129
|
|
|
$em->persist($record); |
|
130
|
|
|
|
|
131
|
|
|
return $request->getUid(); |
|
132
|
|
|
|
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
} |
|
136
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.