1 | <?php |
||
37 | class Process |
||
38 | { |
||
39 | const STATE_RUNNING = 'running'; |
||
40 | const STATE_CANCELLED = 'cancelled'; |
||
41 | const STATE_COMPLETED = 'completed'; |
||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $row; |
||
47 | |||
48 | /** |
||
49 | * @var QueueRepository |
||
50 | */ |
||
51 | protected $queueRepository; |
||
52 | |||
53 | /** |
||
54 | * @param array $row |
||
55 | */ |
||
56 | 16 | public function __construct($row = []) |
|
57 | { |
||
58 | 16 | $this->row = $row; |
|
59 | 16 | $objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
|
60 | 16 | $this->queueRepository = $objectManager->get(QueueRepository::class); |
|
61 | 16 | } |
|
62 | |||
63 | /** |
||
64 | * Returns the activity state for this process |
||
65 | * |
||
66 | * @param void |
||
67 | * @return boolean |
||
68 | */ |
||
69 | 1 | public function getActive() |
|
70 | { |
||
71 | 1 | return $this->row['active']; |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * Returns the identifier for the process |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | 16 | public function getProcess_id() |
|
80 | { |
||
81 | 16 | return $this->row['process_id']; |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * Returns the timestamp of the exectime for the first relevant queue item. |
||
86 | * This can be used to determine the runtime |
||
87 | * |
||
88 | * @return int |
||
89 | */ |
||
90 | 1 | public function getTimeForFirstItem() |
|
91 | { |
||
92 | 1 | $entry = $this->queueRepository->findYoungestEntryForProcess($this); |
|
93 | 1 | return $entry->getExecutionTime(); |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * Returns the timestamp of the exectime for the last relevant queue item. |
||
98 | * This can be used to determine the runtime |
||
99 | * |
||
100 | * @return int |
||
101 | */ |
||
102 | 1 | public function getTimeForLastItem() |
|
103 | { |
||
104 | 1 | $entry = $this->queueRepository->findOldestEntryForProcess($this); |
|
105 | 1 | return $entry->getExecutionTime(); |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * Returns the difference between first and last processed item |
||
110 | * |
||
111 | * @return int |
||
112 | */ |
||
113 | 5 | public function getRuntime() |
|
114 | { |
||
115 | 5 | return $this->getTimeForLastItem() - $this->getTimeForFirstItem(); |
|
116 | } |
||
117 | |||
118 | /** |
||
119 | * Returns the ttl of the process |
||
120 | * |
||
121 | * @return int |
||
122 | */ |
||
123 | 1 | public function getTTL() |
|
124 | { |
||
125 | 1 | return $this->row['ttl']; |
|
126 | } |
||
127 | |||
128 | /** |
||
129 | * Counts the number of items which need to be processed |
||
130 | * |
||
131 | * @return int |
||
132 | * @codeCoverageIgnore |
||
133 | */ |
||
134 | public function countItemsProcessed() |
||
138 | |||
139 | /** |
||
140 | * Counts the number of items which still need to be processed |
||
141 | * |
||
142 | * @return int |
||
143 | * @codeCoverageIgnore |
||
144 | */ |
||
145 | public function countItemsToProcess() |
||
149 | |||
150 | /** |
||
151 | * Returns the Progress of a crawling process as a percentage value |
||
152 | * |
||
153 | * @return float |
||
154 | */ |
||
155 | 5 | public function getProgress() |
|
156 | { |
||
169 | |||
170 | /** |
||
171 | * Returns the number of assigned entries |
||
172 | * |
||
173 | * @return int |
||
174 | */ |
||
175 | 1 | public function countItemsAssigned() |
|
179 | |||
180 | /** |
||
181 | * Return the processes current state |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | 4 | public function getState() |
|
196 | |||
197 | /** |
||
198 | * Returns the properties of the object as array |
||
199 | * |
||
200 | * @return array |
||
201 | */ |
||
202 | 1 | public function getRow() |
|
206 | |||
207 | /** |
||
208 | * @param array $row |
||
209 | * |
||
210 | * @return void |
||
211 | */ |
||
212 | 20 | public function setRow(array $row) |
|
216 | } |
||
217 |