Skip to content

Commit

Permalink
Only send if callback exists
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Nov 14, 2024
1 parent fc2f548 commit be4e07a
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/controllers/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit be4e07a

Please sign in to comment.