MCPcopy Index your code
hub / github.com/simstudioai/sim / flush

Function flush

apps/sim/lib/analytics/profound.ts:44–76  ·  view source on GitHub ↗

* Flushes buffered log entries to Profound's API.

()

Source from the content-addressed store, hash-verified

42 * Flushes buffered log entries to Profound's API.
43 */
44async function flush(): Promise<void> {
45 if (buffer.length === 0) return
46
47 const apiKey = env.PROFOUND_API_KEY
48 if (!apiKey) {
49 buffer = []
50 return
51 }
52
53 const endpoint = env.PROFOUND_ENDPOINT
54 if (!endpoint) {
55 buffer = []
56 return
57 }
58 const entries = buffer.splice(0, MAX_BATCH_SIZE)
59
60 try {
61 const response = await fetch(endpoint, {
62 method: 'POST',
63 headers: {
64 'x-api-key': apiKey,
65 'Content-Type': 'application/json',
66 },
67 body: JSON.stringify(entries),
68 })
69
70 if (!response.ok) {
71 logger.error(`Profound API returned ${response.status}`)
72 }
73 } catch (error) {
74 logger.error('Failed to flush logs to Profound', error)
75 }
76}
77
78function ensureFlushTimer(): void {
79 if (flushTimer) return

Callers 2

ensureFlushTimerFunction · 0.70
sendToProfoundFunction · 0.70

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected