MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / main

Function main

scripts/seed-events.mjs:526–594  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

524// ---------------------------------------------------------------------------
525
526async function main() {
527 console.log(`\nSeeding ${SESSION_COUNT} sessions over ${TIMELINE_MINUTES} minutes`);
528 console.log(`API: ${TRACK_URL}`);
529 console.log(`Client ID: ${CLIENT_ID}\n`);
530
531 let totalEvents = 0;
532 let errors = 0;
533
534 const sessionTasks = Array.from({ length: SESSION_COUNT }, (_, i) => async () => {
535 const session = buildSession(i);
536 const scheduledEvents = scheduleSession(session, i, SESSION_COUNT);
537 const { identity, group, ua, ip } = session;
538
539 // 1. Identify
540 try {
541 await sendEvent({ type: 'identify', payload: identity }, ua, ip);
542 } catch (e) {
543 errors++;
544 console.error(` [ERROR] identify session ${i}:`, e.message);
545 }
546
547 // 2. Group (if applicable)
548 if (group) {
549 try {
550 await sendEvent({ type: 'group', payload: { ...group, profileId: identity.profileId } }, ua, ip);
551 } catch (e) {
552 errors++;
553 console.error(` [ERROR] group session ${i}:`, e.message);
554 }
555 }
556
557 // 3. Track events in order
558 for (const ev of scheduledEvents) {
559 const trackPayload = {
560 name: ev.name,
561 profileId: identity.profileId,
562 properties: {
563 ...ev.props,
564 __timestamp: new Date(ev.timestamp).toISOString(),
565 ...(group ? { __group: group.id } : {}),
566 },
567 groups: group ? [group.id] : [],
568 };
569
570 if (ev.revenue) {
571 trackPayload.properties.__revenue = ev.props.revenue;
572 }
573
574 try {
575 await sendEvent({ type: 'track', payload: trackPayload }, ua, ip);
576 totalEvents++;
577 } catch (e) {
578 errors++;
579 console.error(` [ERROR] track ${ev.name} session ${i}:`, e.message);
580 }
581 }
582
583 if ((i + 1) % 50 === 0 || i + 1 === SESSION_COUNT) {

Callers 1

seed-events.mjsFile · 0.70

Calls 7

scheduleSessionFunction · 0.85
sendEventFunction · 0.85
withConcurrencyFunction · 0.85
buildSessionFunction · 0.70
logMethod · 0.45
fromMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected