MCPcopy Create free account
hub / github.com/Rello/analytics / executeBySchedule

Method executeBySchedule

lib/Service/DataloadService.php:169–222  ·  view source on GitHub ↗

* execute all data loads depending on their schedule * Daily or Hourly * * @param $schedule * @return void * @throws Exception */

($schedule)

Source from the content-addressed store, hash-verified

167 * @throws Exception
168 */
169 public function executeBySchedule($schedule)
170 {
171 $schedules = $this->DataloadMapper->getDataloadBySchedule($schedule);
172 $failedDataloadIds = [];
173 foreach ($schedules as $dataload) {
174 try {
175 $result = $this->execute($dataload['id'], null, false);
176 } catch (\Throwable $e) {
177 $failedDataloadIds[] = (int)$dataload['id'];
178 $this->logger->error('Scheduled Analytics data load threw an exception', [
179 'schedule' => (string)$schedule,
180 'dataloadId' => (int)$dataload['id'],
181 'datasetId' => (int)$dataload['dataset'],
182 'datasourceId' => (int)$dataload['datasource'],
183 'exception' => $e,
184 ]);
185 continue;
186 }
187 if ($result['error'] !== 0 && $result['insert'] === 0 && $result['update'] === 0) {
188 // Only notify when the data load failed completely, not when individual records failed.
189 $failedDataloadIds[] = (int)$dataload['id'];
190 $errorMessage = is_string($result['message'] ?? null) && trim($result['message']) !== ''
191 ? $result['message']
192 : 'No detailed error was returned';
193 $logMessage = sprintf(
194 'Scheduled Analytics data load %d for dataset %d failed: %s (insert: %d, update: %d, delete: %d, errors: %d)',
195 (int)$dataload['id'],
196 (int)$dataload['dataset'],
197 $errorMessage,
198 (int)$result['insert'],
199 (int)$result['update'],
200 (int)$result['delete'],
201 (int)$result['error']
202 );
203 $this->logger->error($logMessage, [
204 'schedule' => (string)$schedule,
205 'dataloadId' => (int)$dataload['id'],
206 'datasetId' => (int)$dataload['dataset'],
207 'datasourceId' => (int)$dataload['datasource'],
208 'insert' => (int)$result['insert'],
209 'update' => (int)$result['update'],
210 'delete' => (int)$result['delete'],
211 'error' => (int)$result['error'],
212 'errorMessage' => $errorMessage,
213 ]);
214 $dataset = $this->DatasetService->read($dataload['dataset']);
215 $this->NotificationManager->triggerNotification(NotificationManager::DATALOAD_ERROR, $dataload['dataset'], $dataload['id'], ['dataloadName' => $dataload['name'], 'datasetName' => $dataset['name']], $dataload['user_id']);
216 }
217 }
218
219 if ($failedDataloadIds !== []) {
220 throw new \RuntimeException('Scheduled Analytics data loads failed: ' . implode(', ', $failedDataloadIds));
221 }
222 }
223
224 /**
225 * execute a data load from data source and store into dataset

Callers 7

runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80

Calls 5

executeMethod · 0.95
getDataloadByScheduleMethod · 0.80
triggerNotificationMethod · 0.80
errorMethod · 0.45
readMethod · 0.45