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