Skip to content
Snippets Groups Projects
Commit 7aa4953f authored by ali asaria's avatar ali asaria
Browse files

resolve async call after server starts

parent 94d679af
Branches
Tags
No related merge requests found
......@@ -113,7 +113,7 @@ export async function startLocalServer() {
const server_dir = await getTransformerLabCodeDir();
const logFilePath = await getLogFilePath();
const out = fs.openSync(logFilePath, 'a');
const err = fs.openSync(logFilePath, 'a');
// const err = fs.openSync(logFilePath, 'a');
// Need to call bash script through WSL on Windows
// Windows will not let you set a UNC directory to cwd
......@@ -124,11 +124,11 @@ export async function startLocalServer() {
: ['-l', path.join(server_dir, 'run.sh')];
const options = isPlatformWindows()
? {
stdio: ['ignore', out, err],
// stdio: ['ignore', out, err],
}
: {
cwd: server_dir,
stdio: ['ignore', out, err],
// stdio: ['ignore', out, err],
shell: '/bin/bash',
};
......@@ -143,9 +143,20 @@ export async function startLocalServer() {
if (localServer.stderr) {
localServer.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
fs.writeSync(out, data);
if (data.includes('Uvicorn running on')) {
console.log('Server is running');
resolve({ status: 'success', code: 0 });
}
});
}
localServer.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
fs.writeSync(out, data);
});
localServer.on('error', (error_msg) => {
console.log(`child process failed: ${error_msg}`);
err_msg = error_msg;
......
......@@ -40,7 +40,7 @@ function setIntervalXTimes(
) {
var x = 0;
var intervalID = window.setInterval(async function () {
console.log(`Testing if ${checkName} ${x} times`);
console.log(`Testing if ${checkName} ${x} of ${repetitions} times`);
const response = await callback();
if (response) {
......@@ -333,6 +333,7 @@ function RunServer({ activeStep, setActiveStep }) {
return;
}
console.log('Starting Server');
const start_process =
await window.electron.ipcRenderer.invoke(
'server:startLocalServer'
......@@ -345,7 +346,12 @@ function RunServer({ activeStep, setActiveStep }) {
setThinking(false);
return;
}
// set interval to check if server is running every 2 seconds, 15 times:
console.log('Server has started');
console.log(
'Start checking if the server is running after 0.150 seconds, 25 times'
);
// set interval to check if server is running every 1 seconds, 25 times:
setIntervalXTimes(
'Server is Running on Port 8000',
async () => {
......@@ -364,7 +370,7 @@ function RunServer({ activeStep, setActiveStep }) {
);
setThinking(false);
},
1000,
150,
25
);
}}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment