1
|
|
|
<?php namespace Comodojo\Extender\Socket; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Extender\Queue\Manager; |
4
|
|
|
use \Comodojo\Daemon\Process; |
5
|
|
|
use \Comodojo\Extender\Task\Request; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @package Comodojo Extender |
9
|
|
|
* @author Marco Giovinazzi <[email protected]> |
10
|
|
|
* @license MIT |
11
|
|
|
* |
12
|
|
|
* LICENSE: |
13
|
|
|
* |
14
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
17
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
19
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
20
|
|
|
* THE SOFTWARE. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
class QueueCommands { |
24
|
|
|
|
25
|
|
|
public function queueAdd(Process $daemon, Request $request = null) { |
26
|
|
|
|
27
|
|
|
return self::getManager($daemon)->add($request); |
|
|
|
|
28
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function queueAddBulk(Process $daemon, array $requests = []) { |
32
|
|
|
|
33
|
|
|
return self::getManager($daemon)->addBulk($requests); |
34
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function queueInfo(Process $daemon, $data = null) { |
|
|
|
|
38
|
|
|
|
39
|
|
|
$configuration = $daemon->getConfiguration(); |
|
|
|
|
40
|
|
|
$base_path = $configuration->get('base-path'); |
41
|
|
|
$lock_path = $configuration->get('run-path'); |
42
|
|
|
$lock_file = "$base_path/$lock_path/queue.worker.lock"; |
43
|
|
|
|
44
|
|
|
return unserialize(file_get_contents($lock_file)); |
45
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected static function getManager(Process $daemon) { |
49
|
|
|
|
50
|
|
|
return new Manager( |
51
|
|
|
$daemon->getConfiguration(), |
|
|
|
|
52
|
|
|
$daemon->getLogger(), |
53
|
|
|
$daemon->getEvents() |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):