1 | <?php |
||
35 | class Process |
||
36 | { |
||
37 | const STATE_RUNNING = 'running'; |
||
38 | const STATE_CANCELLED = 'cancelled'; |
||
39 | const STATE_COMPLETED = 'completed'; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $row; |
||
45 | |||
46 | /** |
||
47 | * @param array $row |
||
48 | */ |
||
49 | 14 | public function __construct($row = []) |
|
53 | |||
54 | /** |
||
55 | * Returns the activity state for this process |
||
56 | * |
||
57 | * @param void |
||
58 | * @return boolean |
||
59 | */ |
||
60 | public function getActive() |
||
61 | { |
||
62 | return $this->row['active']; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Returns the identifier for the process |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | 14 | public function getProcess_id() |
|
74 | |||
75 | /** |
||
76 | * Returns the timestamp of the exectime for the first relevant queue item. |
||
77 | * This can be used to determine the runtime |
||
78 | * |
||
79 | * @return int |
||
80 | */ |
||
81 | public function getTimeForFirstItem() |
||
88 | |||
89 | /** |
||
90 | * Returns the timestamp of the exectime for the last relevant queue item. |
||
91 | * This can be used to determine the runtime |
||
92 | * |
||
93 | * @return int |
||
94 | */ |
||
95 | public function getTimeForLastItem() |
||
102 | |||
103 | /** |
||
104 | * Returns the difference between first and last processed item |
||
105 | * |
||
106 | * @return int |
||
107 | */ |
||
108 | public function getRuntime() |
||
109 | { |
||
110 | return $this->getTimeForLastItem() - $this->getTimeForFirstItem(); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * Returns the ttl of the process |
||
115 | * |
||
116 | * @return int |
||
117 | */ |
||
118 | public function getTTL() |
||
119 | { |
||
120 | return $this->row['ttl']; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Counts the number of items which need to be processed |
||
125 | * |
||
126 | * @return int |
||
127 | */ |
||
128 | public function countItemsProcessed() |
||
133 | |||
134 | /** |
||
135 | * Counts the number of items which still need to be processed |
||
136 | * |
||
137 | * @return int |
||
138 | */ |
||
139 | public function countItemsToProcess() |
||
144 | |||
145 | /** |
||
146 | * Returns the Progress of a crawling process as a percentage value |
||
147 | * |
||
148 | * @return float |
||
149 | */ |
||
150 | public function getProgress() |
||
151 | { |
||
152 | $all = $this->countItemsAssigned(); |
||
153 | if ($all <= 0) { |
||
154 | return 0; |
||
155 | } |
||
156 | |||
157 | $res = round((100 / $all) * $this->countItemsProcessed()); |
||
158 | |||
159 | if ($res > 100.0) { |
||
160 | return 100.0; |
||
161 | } |
||
162 | return $res; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * Returns the number of assigned entries |
||
167 | * |
||
168 | * @return int |
||
169 | */ |
||
170 | public function countItemsAssigned() |
||
171 | { |
||
172 | return $this->row['assigned_items_count']; |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * Return the processes current state |
||
177 | * |
||
178 | * @return string |
||
179 | */ |
||
180 | public function getState() |
||
181 | { |
||
182 | if ($this->getActive() && $this->getProgress() < 100) { |
||
183 | $stage = self::STATE_RUNNING; |
||
184 | } elseif (!$this->getActive() && $this->getProgress() < 100) { |
||
185 | $stage = self::STATE_CANCELLED; |
||
186 | } else { |
||
187 | $stage = self::STATE_COMPLETED; |
||
188 | } |
||
189 | return $stage; |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * Returns the properties of the object as array |
||
194 | * |
||
195 | * @return array |
||
196 | */ |
||
197 | public function getRow() |
||
201 | } |
||
202 |