1 | <?php |
||
25 | class tx_crawler_domain_process extends tx_crawler_domain_lib_abstract_dbobject |
||
26 | { |
||
27 | const STATE_RUNNING = 'running'; |
||
28 | const STATE_CANCELLED = 'cancelled'; |
||
29 | const STATE_COMPLETED = 'completed'; |
||
30 | |||
31 | /** |
||
32 | * @var string table name |
||
33 | */ |
||
34 | protected static $tableName = 'tx_crawler_process'; |
||
35 | |||
36 | /** |
||
37 | * Returns the activity state for this process |
||
38 | * |
||
39 | * @param void |
||
40 | * @return boolean |
||
41 | */ |
||
42 | public function getActive() |
||
43 | { |
||
44 | return $this->row['active']; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Returns the identifier for the process |
||
49 | 1 | * |
|
50 | * @return string |
||
51 | 1 | */ |
|
52 | public function getProcess_id() |
||
53 | { |
||
54 | return $this->row['process_id']; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Returns the timestamp of the exectime for the first relevant queue item. |
||
59 | * This can be used to determine the runtime |
||
60 | * |
||
61 | * @return int |
||
62 | */ |
||
63 | public function getTimeForFirstItem() |
||
64 | { |
||
65 | $queueRepository = new tx_crawler_domain_queue_repository(); |
||
66 | $entry = $queueRepository->findYoungestEntryForProcess($this); |
||
67 | |||
68 | return $entry->getExecutionTime(); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Returns the timestamp of the exectime for the last relevant queue item. |
||
73 | * This can be used to determine the runtime |
||
74 | * |
||
75 | * @return int |
||
76 | */ |
||
77 | public function getTimeForLastItem() |
||
78 | { |
||
79 | $queueRepository = new tx_crawler_domain_queue_repository(); |
||
80 | $entry = $queueRepository->findOldestEntryForProcess($this); |
||
81 | |||
82 | return $entry->getExecutionTime(); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Returns the difference between first and last processed item |
||
87 | * |
||
88 | * @return int |
||
89 | */ |
||
90 | public function getRuntime() |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Returns the ttl of the process |
||
97 | * |
||
98 | * @return int |
||
99 | */ |
||
100 | public function getTTL() |
||
101 | { |
||
102 | return $this->row['ttl']; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Counts the number of items which need to be processed |
||
107 | * |
||
108 | * @param void |
||
109 | * @return int |
||
110 | */ |
||
111 | public function countItemsProcessed() |
||
112 | { |
||
113 | $queueRepository = new tx_crawler_domain_queue_repository(); |
||
114 | return $queueRepository->countExecutedItemsByProcess($this); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Counts the number of items which still need to be processed |
||
119 | * |
||
120 | * @param void |
||
121 | * @return int |
||
122 | */ |
||
123 | public function countItemsToProcess() |
||
124 | { |
||
125 | $queueRepository = new tx_crawler_domain_queue_repository(); |
||
126 | return $queueRepository->countNonExecutedItemsByProcess($this); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Returns the Progress of a crawling process as a percentage value |
||
131 | * |
||
132 | * @param void |
||
133 | * @return float |
||
134 | */ |
||
135 | public function getProgress() |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * Returns the number of assigned Entrys |
||
152 | * |
||
153 | * @return int |
||
154 | */ |
||
155 | public function countItemsAssigned() |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * Return the processes current state |
||
162 | * |
||
163 | * @param void |
||
164 | * @return string 'running'|'cancelled'|'completed' |
||
165 | */ |
||
166 | public function getState() |
||
167 | { |
||
168 | if ($this->getActive() && $this->getProgress() < 100) { |
||
169 | $stage = tx_crawler_domain_process::STATE_RUNNING; |
||
170 | } elseif (!$this->getActive() && $this->getProgress() < 100) { |
||
171 | $stage = tx_crawler_domain_process::STATE_CANCELLED; |
||
172 | } else { |
||
178 |