Feat: warn admin before restarting services
This commit is contained in:
parent
a432d913be
commit
6994303069
6 changed files with 126 additions and 8 deletions
|
|
@ -9,7 +9,7 @@ const dbm = require('./postgresql_interface')
|
|||
const configManager = require('./new-config-manager')
|
||||
const settingsLoader = require('./new-settings-loader')
|
||||
|
||||
module.exports = {getMachineName, getMachines, getMachineNames, setMachine}
|
||||
module.exports = {getMachineName, getMachines, getMachine, getMachineNames, setMachine}
|
||||
|
||||
function getMachines () {
|
||||
return db.any('select * from devices where display=TRUE order by created')
|
||||
|
|
@ -88,6 +88,11 @@ function getMachineName (machineId) {
|
|||
.then(it => it.name)
|
||||
}
|
||||
|
||||
function getMachine (machineId) {
|
||||
const sql = 'select * from devices where device_id=$1'
|
||||
return db.oneOrNone(sql, [machineId]).then(res => _.mapKeys(_.camelCase)(res))
|
||||
}
|
||||
|
||||
function renameMachine (rec) {
|
||||
const sql = 'update devices set name=$1 where device_id=$2'
|
||||
return db.none(sql, [rec.newName, rec.deviceId])
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ const logs = require('../../logs')
|
|||
const settingsLoader = require('../../new-settings-loader')
|
||||
const tokenManager = require('../../token-manager')
|
||||
const blacklist = require('../../blacklist')
|
||||
const machineEventsByIdBatch = require("../../postgresql_interface").machineEventsByIdBatch
|
||||
|
||||
const serverVersion = require('../../../package.json').version
|
||||
|
||||
|
|
@ -70,6 +71,7 @@ const typeDefs = gql`
|
|||
cassette1: Int
|
||||
cassette2: Int
|
||||
statuses: [MachineStatus]
|
||||
latestEvent: MachineEvent
|
||||
}
|
||||
|
||||
type Customer {
|
||||
|
|
@ -220,6 +222,16 @@ const typeDefs = gql`
|
|||
address: String!
|
||||
}
|
||||
|
||||
type MachineEvent {
|
||||
id: ID
|
||||
deviceId: String
|
||||
eventType: String
|
||||
note: String
|
||||
created: Date
|
||||
age: Float
|
||||
deviceTime: Date
|
||||
}
|
||||
|
||||
type Query {
|
||||
countries: [Country]
|
||||
currencies: [Currency]
|
||||
|
|
@ -227,6 +239,7 @@ const typeDefs = gql`
|
|||
accountsConfig: [AccountConfig]
|
||||
cryptoCurrencies: [CryptoCurrency]
|
||||
machines: [Machine]
|
||||
machine(deviceId: ID!): Machine
|
||||
customers: [Customer]
|
||||
customer(customerId: ID!): Customer
|
||||
machineLogs(deviceId: ID!, from: Date, until: Date, limit: Int, offset: Int): [MachineLog]
|
||||
|
|
@ -267,6 +280,9 @@ const typeDefs = gql`
|
|||
`
|
||||
|
||||
const transactionsLoader = new DataLoader(ids => transactions.getCustomerTransactionsBatch(ids))
|
||||
const machineEventsLoader = new DataLoader(ids => {
|
||||
return machineEventsByIdBatch(ids)
|
||||
}, { cache: false })
|
||||
|
||||
const notify = () => got.post('http://localhost:3030/dbChange')
|
||||
.catch(e => console.error('Error: lamassu-server not responding'))
|
||||
|
|
@ -278,6 +294,9 @@ const resolvers = {
|
|||
Customer: {
|
||||
transactions: parent => transactionsLoader.load(parent.id)
|
||||
},
|
||||
Machine: {
|
||||
latestEvent: parent => machineEventsLoader.load(parent.deviceId)
|
||||
},
|
||||
Query: {
|
||||
countries: () => countries,
|
||||
currencies: () => currencies,
|
||||
|
|
@ -285,6 +304,7 @@ const resolvers = {
|
|||
accountsConfig: () => accountsConfig,
|
||||
cryptoCurrencies: () => coins,
|
||||
machines: () => machineLoader.getMachineNames(),
|
||||
machine: (...[, { deviceId }]) => machineLoader.getMachine(deviceId),
|
||||
customers: () => customers.getCustomersList(),
|
||||
customer: (...[, { customerId }]) => customers.getCustomerById(customerId),
|
||||
funding: () => funding.getFunding(),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
const _ = require('lodash/fp')
|
||||
const db = require('./db')
|
||||
const pgp = require('pg-promise')()
|
||||
|
||||
function getInsertQuery (tableName, fields) {
|
||||
// outputs string like: '$1, $2, $3...' with proper No of items
|
||||
|
|
@ -48,6 +50,16 @@ exports.machineEvent = function machineEvent (rec) {
|
|||
.then(() => db.none(deleteSql))
|
||||
}
|
||||
|
||||
exports.machineEventsByIdBatch = function machineEventsByIdBatch (machineIds) {
|
||||
const formattedIds = _.map(pgp.as.text, machineIds).join(',')
|
||||
const sql = `SELECT *, (EXTRACT(EPOCH FROM (now() - created))) * 1000 AS age FROM machine_events WHERE device_id IN ($1^) ORDER BY age ASC LIMIT 1`
|
||||
return db.any(sql, [formattedIds]).then(res => {
|
||||
const events = _.map(_.mapKeys(_.camelCase))(res)
|
||||
const eventMap = _.groupBy('deviceId', events)
|
||||
return machineIds.map(id => _.prop([0], eventMap[id]))
|
||||
})
|
||||
}
|
||||
|
||||
exports.machineEvents = function machineEvents () {
|
||||
const sql = 'SELECT *, (EXTRACT(EPOCH FROM (now() - created))) * 1000 AS age FROM machine_events'
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue