1 | <?php |
||
38 | class Process extends AbstractEntity |
||
39 | { |
||
40 | const STATE_RUNNING = 'running'; |
||
41 | const STATE_CANCELLED = 'cancelled'; |
||
42 | const STATE_COMPLETED = 'completed'; |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $row; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $processId = ''; |
||
53 | |||
54 | /** |
||
55 | * @var bool |
||
56 | */ |
||
57 | protected $active = false; |
||
58 | |||
59 | /** |
||
60 | * @var int |
||
61 | */ |
||
62 | protected $ttl = 0; |
||
63 | |||
64 | /** |
||
65 | * @var int |
||
66 | */ |
||
67 | protected $assignedItemsCount = 0; |
||
68 | |||
69 | /** |
||
70 | * @var bool |
||
71 | */ |
||
72 | protected $deleted = false; |
||
73 | |||
74 | /** |
||
75 | * @var string |
||
76 | */ |
||
77 | protected $systemProcessId = ''; |
||
78 | |||
79 | /** |
||
80 | * @var QueueRepository |
||
81 | */ |
||
82 | protected $queueRepository; |
||
83 | |||
84 | 10 | public function __construct() |
|
89 | |||
90 | /** |
||
91 | * @return string |
||
92 | */ |
||
93 | 9 | public function getProcessId() |
|
97 | |||
98 | /** |
||
99 | * @param string $processId |
||
100 | */ |
||
101 | 26 | public function setProcessId($processId) |
|
105 | |||
106 | /** |
||
107 | * @return bool |
||
108 | */ |
||
109 | 1 | public function isActive() |
|
113 | |||
114 | /** |
||
115 | * @param bool $active |
||
116 | */ |
||
117 | 18 | public function setActive($active) |
|
121 | |||
122 | /** |
||
123 | * @return int |
||
124 | */ |
||
125 | 1 | public function getTtl() |
|
129 | |||
130 | /** |
||
131 | * @param int $ttl |
||
132 | */ |
||
133 | 18 | public function setTtl($ttl) |
|
137 | |||
138 | /** |
||
139 | * @return int |
||
140 | */ |
||
141 | 1 | public function getAssignedItemsCount() |
|
145 | |||
146 | /** |
||
147 | * @param int $assignedItemsCount |
||
148 | */ |
||
149 | 18 | public function setAssignedItemsCount($assignedItemsCount) |
|
153 | |||
154 | /** |
||
155 | * @return bool |
||
156 | */ |
||
157 | 1 | public function isDeleted() |
|
161 | |||
162 | /** |
||
163 | * @param bool $deleted |
||
164 | */ |
||
165 | 4 | public function setDeleted($deleted) |
|
169 | |||
170 | /** |
||
171 | * @return string |
||
172 | */ |
||
173 | 1 | public function getSystemProcessId() |
|
177 | |||
178 | /** |
||
179 | * @param string $systemProcessId |
||
180 | */ |
||
181 | 4 | public function setSystemProcessId($systemProcessId) |
|
185 | |||
186 | /** |
||
187 | * Returns the difference between first and last processed item |
||
188 | * |
||
189 | * @return int |
||
190 | */ |
||
191 | 5 | public function getRuntime() |
|
195 | |||
196 | /** |
||
197 | * @return int |
||
198 | */ |
||
199 | public function getTimeForLastItem(): int |
||
204 | |||
205 | /** |
||
206 | * @return int |
||
207 | */ |
||
208 | public function getTimeForFirstItem(): int |
||
213 | |||
214 | /** |
||
215 | * Counts the number of items which need to be processed |
||
216 | * |
||
217 | * @return int |
||
218 | * @codeCoverageIgnore |
||
219 | */ |
||
220 | public function getAmountOfItemsProcessed() |
||
221 | { |
||
222 | return $this->queueRepository->countExecutedItemsByProcess($this); |
||
223 | } |
||
224 | |||
225 | /** |
||
226 | * Counts the number of items which still need to be processed |
||
227 | * |
||
228 | * @return int |
||
229 | * @codeCoverageIgnore |
||
230 | */ |
||
231 | public function getItemsToProcess() |
||
235 | |||
236 | /** |
||
237 | * @return int |
||
238 | */ |
||
239 | public function getFinallyAssigned(): int |
||
243 | |||
244 | /** |
||
245 | * Returns the Progress of a crawling process as a percentage value |
||
246 | * |
||
247 | * @return float |
||
248 | */ |
||
249 | 5 | public function getProgress() |
|
250 | { |
||
251 | 5 | $all = $this->getAssignedItemsCount(); |
|
252 | 5 | if ($all <= 0) { |
|
253 | 2 | return 0; |
|
254 | } |
||
255 | |||
256 | 3 | $res = round((100 / $all) * $this->getAmountOfItemsProcessed()); |
|
257 | |||
258 | 3 | if ($res > 100.0) { |
|
259 | 1 | return 100.0; |
|
260 | } |
||
261 | 2 | return $res; |
|
262 | } |
||
263 | |||
264 | /** |
||
265 | * Return the processes current state |
||
266 | * |
||
267 | * @return string |
||
268 | */ |
||
269 | 4 | public function getState() |
|
280 | } |
||
281 |