1 | <?php |
||
10 | class JobManager extends AbstractJobManager |
||
11 | { |
||
12 | /** @var AMQPChannel */ |
||
13 | protected $channel; |
||
14 | |||
15 | /** @var AbstractConnection */ |
||
16 | protected $connection; |
||
17 | protected $queueArgs; |
||
18 | protected $exchangeArgs; |
||
19 | |||
20 | protected $channelSetup = false; |
||
21 | |||
22 | protected $hostname; |
||
23 | protected $pid; |
||
24 | protected $maxPriority; |
||
25 | |||
26 | 2 | public function __construct() |
|
27 | { |
||
28 | 2 | $this->hostname = gethostname() ?: ''; |
|
29 | 2 | $this->pid = getmypid(); |
|
30 | 2 | } |
|
31 | |||
32 | /** |
||
33 | * @param string $exchange |
||
34 | * @param string $type |
||
35 | * @param bool $passive |
||
36 | * @param bool $durable |
||
37 | * @param bool $autoDelete |
||
38 | */ |
||
39 | 1 | public function setExchangeArgs($exchange, $type, $passive, $durable, $autoDelete) |
|
40 | { |
||
41 | 1 | $this->exchangeArgs = [$exchange, $type, $passive, $durable, $autoDelete]; |
|
42 | 1 | } |
|
43 | |||
44 | /** |
||
45 | * @param string $queue |
||
46 | * @param bool $passive |
||
47 | * @param bool $durable |
||
48 | * @param bool $exclusive |
||
49 | * @param bool $autoDelete |
||
50 | * @param int $maxPriority |
||
51 | */ |
||
52 | 1 | public function setQueueArgs($queue, $passive, $durable, $exclusive, $autoDelete, $maxPriority) |
|
53 | { |
||
54 | 1 | $arguments = [$queue, $passive, $durable, $exclusive, $autoDelete]; |
|
55 | |||
56 | 1 | $this->queueArgs = $arguments; |
|
57 | 1 | if (!ctype_digit(strval($maxPriority))) { |
|
58 | 1 | throw new \Exception('Max Priority needs to be a non-negative integer'); |
|
59 | } |
||
60 | 1 | if (strval(intval($maxPriority)) !== strval($maxPriority)) { |
|
61 | 1 | throw new \Exception('Priority is higher than '.PHP_INT_MAX); |
|
62 | } |
||
63 | 1 | $this->maxPriority = $maxPriority; |
|
64 | 1 | } |
|
65 | |||
66 | 1 | public function setAMQPConnection(AbstractConnection $connection) |
|
67 | { |
||
68 | 1 | $this->connection = $connection; |
|
69 | 1 | $this->channel = $connection->channel(); |
|
70 | 1 | } |
|
71 | |||
72 | /** |
||
73 | * @return AMQPChannel |
||
74 | */ |
||
75 | public function getChannel() |
||
79 | |||
80 | 6 | public function setupChannel() |
|
81 | { |
||
82 | 6 | if (empty($this->queueArgs)) { |
|
83 | 1 | throw new \Exception(__METHOD__.': queue args need to be set via setQueueArgs(...)'); |
|
100 | |||
101 | 5 | /** |
|
102 | * @param \Dtc\QueueBundle\Model\Job $job |
||
103 | 5 | * |
|
104 | 5 | * @return \Dtc\QueueBundle\Model\Job |
|
105 | 5 | * |
|
106 | * @throws \Exception |
||
107 | */ |
||
108 | 5 | public function save(\Dtc\QueueBundle\Model\Job $job) |
|
126 | |||
127 | /** |
||
128 | * Attach a unique id to a job since RabbitMQ will not. |
||
129 | * |
||
130 | 6 | * @param \Dtc\QueueBundle\Model\Job $job |
|
131 | */ |
||
132 | 6 | protected function setJobId(\Dtc\QueueBundle\Model\Job $job) |
|
138 | 5 | ||
139 | /** |
||
140 | 5 | * Sets the priority of the AMQPMessage. |
|
141 | 5 | * |
|
142 | 5 | * @param AMQPMessage $msg |
|
143 | * @param \Dtc\QueueBundle\Model\Job $job |
||
144 | 5 | */ |
|
145 | protected function setMsgPriority(AMQPMessage $msg, \Dtc\QueueBundle\Model\Job $job) |
||
158 | 5 | ||
159 | 5 | /** |
|
160 | * @param \Dtc\QueueBundle\Model\Job $job |
||
161 | 5 | * |
|
162 | 1 | * @throws \Exception |
|
163 | 1 | */ |
|
164 | protected function validateSaveable(\Dtc\QueueBundle\Model\Job $job) |
||
174 | |||
175 | /** |
||
176 | 1 | * @param string $workerName |
|
177 | */ |
||
178 | 1 | public function getJob($workerName = null, $methodName = null, $prioritize = true, $runId = null) |
|
194 | |||
195 | /** |
||
196 | * @param bool $expiredJob |
||
197 | * @param $runId |
||
198 | * |
||
199 | * @return Job|null |
||
200 | */ |
||
201 | protected function findJob(&$expiredJob, $runId) |
||
222 | |||
223 | // Save History get called upon completion of the job |
||
224 | public function saveHistory(\Dtc\QueueBundle\Model\Job $job) |
||
234 | |||
235 | public function __destruct() |
||
241 | } |
||
242 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.