feat: batch diagnostics script
This commit is contained in:
parent
4c270dcd65
commit
4a00fad44c
3 changed files with 76 additions and 1 deletions
36
packages/server/bin/lamassu-batch-diagnostics
Normal file
36
packages/server/bin/lamassu-batch-diagnostics
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
require('../lib/environment-helper')
|
||||
|
||||
const db = require('../lib/db')
|
||||
const machineLoader = require('../lib/machine-loader')
|
||||
const operator = require('../lib/operator')
|
||||
|
||||
console.log('Running diagnostics on all paired devices...\n')
|
||||
|
||||
operator.getOperatorId('middleware')
|
||||
.then(operatorId => {
|
||||
if (!operatorId) {
|
||||
throw new Error('Operator ID not found in database')
|
||||
}
|
||||
|
||||
return db.any('SELECT device_id, name FROM devices')
|
||||
.then(devices => ({ operatorId, devices }))
|
||||
})
|
||||
.then(({ operatorId, devices }) => {
|
||||
if (devices.length === 0) {
|
||||
console.log('No paired devices found.')
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const deviceIds = devices.map(d => d.device_id)
|
||||
return machineLoader.batchDiagnostics(deviceIds, operatorId)
|
||||
})
|
||||
.then(() => {
|
||||
console.log('\n✓ Diagnostics initiated for all devices. It can take a few minutes for the results to appear on the admin.')
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Error:', err.message)
|
||||
process.exit(1)
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue