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

Function ping

apps/worker/src/jobs/cron.ping.ts:3–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1import { TABLE_NAMES, chQuery } from '@openpanel/db';
2
3export async function ping() {
4 if (process.env.DISABLE_PING) {
5 return;
6 }
7
8 const [res] = await chQuery<{ count: number }>(
9 `SELECT COUNT(*) as count FROM ${TABLE_NAMES.events}`,
10 );
11
12 if (typeof res?.count === 'number') {
13 const response = await fetch('https://api.openpanel.dev/misc/ping', {
14 method: 'POST',
15 headers: {
16 'Content-Type': 'application/json',
17 },
18 body: JSON.stringify({
19 domain:
20 process.env.DASHBOARD_URL || process.env.NEXT_PUBLIC_DASHBOARD_URL,
21 count: res?.count,
22 }),
23 });
24
25 if (response.ok) {
26 return await response.json();
27 }
28
29 throw new Error('Failed to ping the server');
30 }
31}

Callers 1

cronJobFunction · 0.90

Calls 2

fetchFunction · 0.50
stringifyMethod · 0.45

Tested by

no test coverage detected