MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / refresh

Function refresh

packages/cli/src/commands/dev.ts:204–285  ·  view source on GitHub ↗
(options: RefreshOptions)

Source from the content-addressed store, hash-verified

202};
203
204async 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(

Callers 1

rFunction · 0.85

Calls 6

getTriggerApiDetailsFunction · 0.90
waitFunction · 0.90
startIndexingFunction · 0.85
fetchIndexResultFunction · 0.85
errorMethod · 0.65
infoMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…