From be4e07a41bbf89af60498017ff21d217f9567276 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 14 Nov 2024 19:33:10 +0700 Subject: [PATCH] Only send if callback exists --- src/controllers/runner.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/controllers/runner.js b/src/controllers/runner.js index 5a5ccc4..ca3b403 100644 --- a/src/controllers/runner.js +++ b/src/controllers/runner.js @@ -51,6 +51,12 @@ function trimPayload(payload) { return payload; } } +/** + * @param {any} body + * @param {string} domain + * @param {boolean} sandbox + * @param {string} callback + */ export async function runConfigInBackground(body, domain, sandbox, callback) { let fullLogData = [], chunkedLogData = ['Running deployment script... Please wait...\n'], @@ -84,24 +90,24 @@ export async function runConfigInBackground(body, domain, sandbox, callback) { setTimeout(periodicSender, delay).unref(); } } - periodicSender(); + if (callback) { + periodicSender(); + } write.on('data', (chunk) => { if (!callback) return; chunkedLogData.push(chunk); fullLogData.push(chunk); }); write.on('end', () => { - // and finish message with full log - if (callback) { - chunkedLogData = []; - const data = trimPayload(normalizeShellOutput(fullLogData)); - request(callback, { data, headers, ...options }) - .then(e => { - console.log('callback response:', e.statusCode) - }).catch(e => { - console.error(e); - }); - } + if (!callback) return; + chunkedLogData = []; + const data = trimPayload(normalizeShellOutput(fullLogData)); + request(callback, { data, headers, ...options }) + .then(e => { + console.log('callback response:', e.statusCode) + }).catch(e => { + console.error(e); + }); }); try { await runConfig(body || {}, domain + "", (s) => {