MCPcopy Create free account
hub / github.com/vercel/vercel / printEvents

Function printEvents

packages/cli/src/util/events.ts:32–198  ·  view source on GitHub ↗
(
  client: Client,
  urlOrDeploymentId: string,
  { mode, onEvent, quiet, findOpts }: PrintEventsOptions,
  abortController?: AbortController
)

Source from the content-addressed store, hash-verified

30}
31
32async function printEvents(
33 client: Client,
34 urlOrDeploymentId: string,
35 { mode, onEvent, quiet, findOpts }: PrintEventsOptions,
36 abortController?: AbortController
37) {
38 const { log, debug } = output;
39 const scope = mode === 'deploy' ? await getScope(client) : null;
40
41 // we keep track of how much we log in case we
42 // drop the connection and have to start over
43 let o = 0;
44
45 await retry(
46 async (bail, attemptNumber) => {
47 if (attemptNumber > 1) {
48 debug('Retrying events');
49 }
50
51 const query = new URLSearchParams({
52 direction: findOpts.direction,
53 follow: findOpts.follow ? '1' : '',
54 format: 'lines',
55 });
56 if (findOpts.limit) query.set('limit', String(findOpts.limit));
57 if (findOpts.since) query.set('since', String(findOpts.since));
58 if (findOpts.until) query.set('until', String(findOpts.until));
59
60 const eventsUrl = `/v3/now/deployments/${urlOrDeploymentId}/events?${query}`;
61 try {
62 const eventsRes = await client.fetch(eventsUrl, {
63 json: false,
64 signal: abortController?.signal,
65 });
66
67 if (eventsRes.ok) {
68 const readable = toNodeReadable(eventsRes.body);
69
70 // handle the event stream and make the promise get rejected
71 // if errors occur so we can retry
72 return new Promise<void>((resolve, reject) => {
73 const stream = readable.pipe(jsonlines.parse());
74
75 let poller: ReturnType<typeof setTimeout>;
76
77 if (mode === 'deploy') {
78 poller = (function startPoller() {
79 return setTimeout(async () => {
80 try {
81 const json = await getDeployment(
82 client,
83 scope!.contextName,
84 urlOrDeploymentId
85 );
86 if (json.readyState === 'READY') {
87 stream.end();
88 finish();
89 return;

Callers 4

displayBuildLogsFunction · 0.85
onErrorFunction · 0.85
processDeploymentFunction · 0.85

Calls 12

toNodeReadableFunction · 0.90
getScopeFunction · 0.85
retryFunction · 0.85
getDeploymentFunction · 0.85
bailFunction · 0.85
eraseLinesFunction · 0.85
finishFunction · 0.70
debugFunction · 0.50
setMethod · 0.45
fetchMethod · 0.45
parseMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected