(options: RefreshOptions)
| 202 | }; |
| 203 | |
| 204 | async function refresh(options: RefreshOptions) { |
| 205 | //stop any existing refreshes |
| 206 | options.abortController.abort(); |
| 207 | options.abortController = new AbortController(); |
| 208 | |
| 209 | // Read from env file to get the TRIGGER_API_KEY and TRIGGER_API_URL |
| 210 | const apiDetails = await getTriggerApiDetails(options.path, options.resolvedOptions.envFile); |
| 211 | if (!apiDetails) { |
| 212 | options.spinner.fail("[trigger.dev] Failed to connect: Missing API Key"); |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | const { apiKey, apiUrl } = apiDetails; |
| 217 | const apiClient = new TriggerApi(apiKey, apiUrl); |
| 218 | |
| 219 | try { |
| 220 | const index = await pRetry(() => startIndexing({ ...options, apiClient }), { |
| 221 | retries: 5, |
| 222 | signal: options.abortController.signal, |
| 223 | maxTimeout: 5000, |
| 224 | }); |
| 225 | options.spinner.text = `[trigger.dev] Refreshing ${formattedDate.format(index.updatedAt)}`; |
| 226 | |
| 227 | if (!options.hasConnected) { |
| 228 | options.hasConnected = true; |
| 229 | telemetryClient.dev.connected(options.path, options.resolvedOptions); |
| 230 | } |
| 231 | |
| 232 | //this is for backwards-compatibility with older servers |
| 233 | if (index.id === undefined) { |
| 234 | options.spinner.succeed(`[trigger.dev] Refreshed ${formattedDate.format(index.updatedAt)}`); |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | //wait 750ms before attempting to get the indexing result |
| 239 | await wait(750); |
| 240 | |
| 241 | const indexResult = await pRetry(() => fetchIndexResult({ indexId: index.id, apiClient }), { |
| 242 | //this means we're polling, same distance between each attempt |
| 243 | factor: 1, |
| 244 | retries: 10, |
| 245 | signal: options.abortController.signal, |
| 246 | }); |
| 247 | |
| 248 | if (indexResult.status === "FAILURE") { |
| 249 | options.spinner.fail( |
| 250 | `[trigger.dev] Refreshing failed ${formattedDate.format(indexResult.updatedAt)}` |
| 251 | ); |
| 252 | logger.error( |
| 253 | boxen(indexResult.error.message, { |
| 254 | padding: 1, |
| 255 | borderStyle: "double", |
| 256 | }) |
| 257 | ); |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | options.spinner.succeed( |
no test coverage detected
searching dependent graphs…