From 656bcc2a8c071f9816c3c65b7d9b38b165a50f51 Mon Sep 17 00:00:00 2001 From: Aleksandar Acic Date: Wed, 13 Mar 2024 16:22:07 -0500 Subject: [PATCH] Change a server_stat method to poll the server --- server/src/blat.js | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/server/src/blat.js b/server/src/blat.js index 3127954c5c..4fee7f9faa 100644 --- a/server/src/blat.js +++ b/server/src/blat.js @@ -32,29 +32,17 @@ export function request_closure(genomes) { } function server_stat(name, g) { - return new Promise((resolve, reject) => { - // TODO rector this to simulate server stat by running a client request - const ps = spawn(serverconfig.gfServer, ['status', g.blat.host, g.blat.port]) - const out = [], - out2 = [] - ps.stdout.on('data', i => out.push(i)) - ps.stderr.on('data', i => out2.push(i)) - ps.on('close', code => { - const e = out2.join('').trim() - if (e) { - resolve(name + ' OFF') - } - const lines = out.join('').trim().split('\n') - let c = 0 - for (const line of lines) { - if (line.startsWith('blat requests')) c = line.split(' ')[2] - } - resolve(name + ' ON, ' + c + ' requests') - }) - - ps.on('error', err => { - reject('Error spawning gfServer: ' + err.message) - }) + return new Promise(async (resolve, reject) => { + // query a random sequence to see if the server is up + const infile = path.join(serverconfig.cachedir, await write_tmpfile('>query\n' + 'ATCG' + '\n')) + try { + await run_blat2(g, infile) + console.log('g', g) + resolve(`ON for ${g.blat.host} ${g.blat.port}`) + } catch (e) { + console.log('g', g) + reject(`OFF for ${g.blat.host} ${g.blat.port}`) + } }) }