1
|
|
|
<?php namespace Comodojo\Extender; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Extender\Workers\ScheduleWorker; |
4
|
|
|
use \Comodojo\Extender\Workers\QueueWorker; |
5
|
|
|
use \Comodojo\Daemon\Daemon as AbstractDaemon; |
6
|
|
|
use \Comodojo\Dispatcher\Traits\EventsTrait; |
7
|
|
|
use \Comodojo\Dispatcher\Traits\LoggerTrait; |
8
|
|
|
use \Comodojo\Dispatcher\Traits\CacheTrait; |
9
|
|
|
use \Comodojo\Dispatcher\Traits\ConfigurationTrait; |
10
|
|
|
use \Comodojo\Foundation\Events\Manager as EventsManager; |
11
|
|
|
use \Comodojo\Foundation\Base\Configuration; |
12
|
|
|
use \Comodojo\SimpleCache\Manager as SimpleCacheManager; |
13
|
|
|
use \Comodojo\Foundation\Logging\Manager as LogManager; |
14
|
|
|
use \Psr\Log\LoggerInterface; |
15
|
|
|
|
16
|
|
|
class ExtenderDaemon extends AbstractDaemon { |
17
|
|
|
|
18
|
|
|
use ConfigurationTrait; |
19
|
|
|
use EventsTrait; |
20
|
|
|
use LoggerTrait; |
21
|
|
|
use CacheTrait; |
22
|
|
|
|
23
|
|
|
protected static $default_properties = array( |
24
|
|
|
'pidfile' => 'extender.pid', |
25
|
|
|
'socketfile' => 'unix://extender.sock', |
26
|
|
|
'socketbuffer' => 8192, |
27
|
|
|
'sockettimeout' => 15, |
28
|
|
|
'niceness' => 0, |
29
|
|
|
'arguments' => '\\Comodojo\\Daemon\\Console\\DaemonArguments', |
30
|
|
|
'description' => 'Extender Daemon' |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
public function __construct( |
34
|
|
|
array $configuration = [], |
35
|
|
|
EventsManager $events = null, |
36
|
|
|
SimpleCacheManager $cache = null, |
37
|
|
|
LoggerInterface $logger = null |
38
|
|
|
) { |
39
|
|
|
|
40
|
|
|
$this->configuration = new Configuration(self::$default_properties); |
41
|
|
|
$this->configuration->merge($configuration); |
42
|
|
|
|
43
|
|
|
// $this->logger = is_null($logger) ? LogManager::createFromConfiguration($this->configuration)->getLogger() : $logger; |
|
|
|
|
44
|
|
|
|
45
|
|
|
try { |
|
|
|
|
46
|
|
|
// init other components |
47
|
|
|
//$this->setEvents(is_null($events) ? EventsManager::create($this->logger) : $events); |
|
|
|
|
48
|
|
|
|
49
|
|
|
} catch (Exception $e) { |
|
|
|
|
50
|
|
|
throw $e; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
parent::__construct($this->configuration->get(), $logger, $events); |
54
|
|
|
|
55
|
|
|
$this->setCache(is_null($cache) ? SimpleCacheManager::createFromConfiguration($this->configuration, $this->logger) : $cache); |
56
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function setup() { |
60
|
|
|
|
61
|
|
|
// add workers |
62
|
|
|
$manager = $this->getWorkers(); |
63
|
|
|
$schedule_worker = new ScheduleWorker("schedule"); |
64
|
|
|
$queue_worker = new QueueWorker("queue"); |
65
|
|
|
$manager->install($schedule_worker, 1, true) |
66
|
|
|
->install($queue_worker, 1, true); |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.