Skip to content

Commit

Permalink
Change a server_stat method to poll the server
Browse files Browse the repository at this point in the history
  • Loading branch information
aacic committed Mar 13, 2024
1 parent b91521c commit 656bcc2
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions server/src/blat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
})
}

Expand Down

0 comments on commit 656bcc2

Please sign in to comment.