Import the got module only once + fix console statement

pull/5152/head
GogoVega 2025-06-04 15:44:16 +02:00
parent 30215b02ac
commit bb49fc6c16
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B
1 changed files with 8 additions and 2 deletions

View File

@ -6,6 +6,9 @@ const cronosjs = require('cronosjs')
const METRICS_DIR = path.join(__dirname, 'metrics')
const INITIAL_PING_DELAY = 1000 * 60 * 30 // 30 minutes from startup
/** @type {import("got").Got | undefined} */
let got
let runtime
let scheduleTask
@ -48,11 +51,14 @@ async function report () {
}
// If enabled, gather metrics
const metrics = await gather()
console.log(JSON.stringify(metrics, null, 2))
runtime.log.debug(`Telemetry metrics: ${JSON.stringify(metrics, null, 2)}`)
// Post metrics to endpoint - handle any error silently
const { got } = await import('got')
if (!got) {
got = (await import('got')).got
}
runtime.log.debug('Sending telemetry')
const response = await got.post('https://telemetry.nodered.org/ping', {
json: metrics,