committed by
GitHub
parent
f0b7526847
commit
df05e2dab3
26
apps/worker/src/jobs/cron.ping.ts
Normal file
26
apps/worker/src/jobs/cron.ping.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { chQuery, TABLE_NAMES } from '@openpanel/db';
|
||||
|
||||
export async function ping() {
|
||||
const [res] = await chQuery<{ count: number }>(
|
||||
`SELECT COUNT(*) as count FROM ${TABLE_NAMES.events}`
|
||||
);
|
||||
|
||||
if (typeof res?.count === 'number') {
|
||||
const response = await fetch('https://api.openpanel.com/misc/ping', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
domain: process.env.NEXT_PUBLIC_DASHBOARD_URL,
|
||||
count: res?.count,
|
||||
}),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
throw new Error('Failed to ping the server');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user