@sjcrh/proteinpaint-server 2.24.1 → 2.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +19 -5
- package/server.js +1 -1
- package/src/routes/healthcheck.ts +92 -0
- package/utils/cuminc.R +9 -7
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import serverconfig from '../serverconfig'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import child_process from 'child_process'
|
|
4
|
+
import util from 'util'
|
|
5
|
+
import pkg from '../../package.json'
|
|
6
|
+
import { VersionInfo, GenomeBuildInfo, HealthCheckResponse } from '../../shared/types/healthcheck'
|
|
7
|
+
|
|
8
|
+
const execPromise = util.promisify(child_process.exec)
|
|
9
|
+
//const docs = require('../shared/doc')
|
|
10
|
+
|
|
11
|
+
export function setRoute(app: any, genomes: any, basepath) {
|
|
12
|
+
app.get(basepath + '/healthcheck', async (req, res): Promise<void> => {
|
|
13
|
+
try {
|
|
14
|
+
const health = await getStat(genomes)
|
|
15
|
+
res.send(health)
|
|
16
|
+
} catch (e: any) {
|
|
17
|
+
res.send({ status: 'error', error: e.message || e })
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function getStat(genomes: any): Promise<HealthCheckResponse> {
|
|
23
|
+
const health = {
|
|
24
|
+
status: 'ok',
|
|
25
|
+
genomes: {},
|
|
26
|
+
versionInfo
|
|
27
|
+
} as HealthCheckResponse
|
|
28
|
+
|
|
29
|
+
const keys = serverconfig.features.healthcheck_keys || []
|
|
30
|
+
|
|
31
|
+
if (keys.includes('w')) {
|
|
32
|
+
const { stdout, stderr } = await execPromise('w | head -n1')
|
|
33
|
+
if (stderr) throw stderr
|
|
34
|
+
health.w = stdout
|
|
35
|
+
.toString()
|
|
36
|
+
.trim()
|
|
37
|
+
.split(' ')
|
|
38
|
+
.slice(-3)
|
|
39
|
+
.map(d => (d.endsWith(',') ? +d.slice(0, -1) : +d))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (keys.includes('rs')) {
|
|
43
|
+
const { stdout, stderr } = await execPromise('ps aux | grep rsync -w')
|
|
44
|
+
if (stderr) throw stderr
|
|
45
|
+
health.rs = stdout.toString().trim().split('\n').length - 1
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// report status of every genome
|
|
49
|
+
for (const gn in genomes) {
|
|
50
|
+
const genome = genomes[gn] //; console.log(genome.genedb)
|
|
51
|
+
const dbInfo = {} as GenomeBuildInfo // object to store status of this genome
|
|
52
|
+
|
|
53
|
+
if (genome.genedb) {
|
|
54
|
+
// genedb status
|
|
55
|
+
dbInfo.genedb = {
|
|
56
|
+
buildDate: genome.genedb.get_buildDate?.get().date || 'unknown',
|
|
57
|
+
tables: genome.genedb.tableSize
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (genome.termdbs) {
|
|
62
|
+
// genome-level termdb status e.g. msigdb
|
|
63
|
+
dbInfo.termdbs = {}
|
|
64
|
+
for (const key in genome.termdbs) {
|
|
65
|
+
const db = genome.termdbs[key]
|
|
66
|
+
dbInfo.termdbs[key] = {
|
|
67
|
+
buildDate: db.cohort.termdb.q.get_buildDate?.get().date || 'unknown'
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (Object.keys(dbInfo).length && health.genomes) health.genomes[gn] = dbInfo
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return health
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const versionInfo: VersionInfo = {
|
|
79
|
+
pkgver: pkg.version,
|
|
80
|
+
codedate: get_codedate(),
|
|
81
|
+
launchdate: new Date(Date.now()).toString().split(' ').slice(0, 5).join(' ')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function get_codedate() {
|
|
85
|
+
const date1 =
|
|
86
|
+
(fs.existsSync('public/bin/proteinpaint.js') && fs.statSync(serverconfig.binpath + '/server.js').mtime) ||
|
|
87
|
+
new Date(0)
|
|
88
|
+
const date2 =
|
|
89
|
+
(fs.existsSync('public/bin/proteinpaint.js') && fs.statSync('public/bin/proteinpaint.js').mtime) || new Date(0)
|
|
90
|
+
const date = date1 > date2 ? date1 : date2
|
|
91
|
+
return date.toDateString()
|
|
92
|
+
}
|
package/utils/cuminc.R
CHANGED
|
@@ -13,13 +13,15 @@
|
|
|
13
13
|
|
|
14
14
|
# Input JSON:
|
|
15
15
|
# {
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
16
|
+
# data:
|
|
17
|
+
# chartId: [
|
|
18
|
+
# {
|
|
19
|
+
# time: time to event
|
|
20
|
+
# event: event code (0 = censored, 1 = event, 2 = competing risk event)
|
|
21
|
+
# series: series ID
|
|
22
|
+
# }
|
|
23
|
+
# ],
|
|
24
|
+
# startTime: custom start time of cuminc curve
|
|
23
25
|
# }
|
|
24
26
|
#
|
|
25
27
|
# Output JSON:
|