Skip to content

Commit

Permalink
Merge pull request #1173 from edenia/dev
Browse files Browse the repository at this point in the history
Production Release
  • Loading branch information
xavier506 authored Apr 28, 2023
2 parents 4660bc2 + 5d9fe3f commit 666195b
Show file tree
Hide file tree
Showing 88 changed files with 940 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .env.proton
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ HASURA_GRAPHQL_ACTION_BASE_URL=http://hapi:9090

# hapi
HAPI_EOS_API_NETWORK_NAME=proton
HAPI_EOS_API_ENDPOINTS=["https://proton.edenia.cloud","https://proton.greymass.com","https://proton.eosphere.io"]
HAPI_EOS_API_ENDPOINTS=["https://proton.edenia.cloud","https://proton.eosusa.io","https://proton.greymass.com","https://proton.eosargentina.io"]
HAPI_EOS_API_CHAIN_ID=384da888112027f0321850a169f737c33e53b388aad48b5adace4bab97f437e0
HAPI_EOS_BASE_ACCOUNT=baseaccount
HAPI_EOS_BASE_ACCOUNT_PASSWORD=PW...
Expand Down Expand Up @@ -70,7 +70,7 @@ REACT_APP_HASURA_URL=http://localhost:8080/v1/graphql
REACT_APP_EOS_API_NETWORK_NAME=proton
REACT_APP_EOS_API_NETWORK_LABEL=Proton
REACT_APP_EOS_API_NETWORK_LOGO=https://antelope.tools/images/proton.png
REACT_APP_EOS_API_HOSTS=["proton.edenia.cloud","proton.greymass.com","proton.eosphere.io"]
REACT_APP_EOS_API_HOSTS=["proton.edenia.cloud","proton.eosusa.io","proton.greymass.com","proton.eosargentina.io"]
REACT_APP_EOS_API_PORT=443
REACT_APP_EOS_API_PROTOCOL=https
REACT_APP_EOS_CHAIN_ID=384da888112027f0321850a169f737c33e53b388aad48b5adace4bab97f437e0
Expand Down
4 changes: 2 additions & 2 deletions .env.protontestnet
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ HASURA_GRAPHQL_ACTION_BASE_URL=http://hapi:9090

# hapi
HAPI_EOS_API_NETWORK_NAME=proton
HAPI_EOS_API_ENDPOINTS=["https://proton-testnet.edenia.cloud","https://test.proton.eosusa.news","https://proton-testnet.eosphere.io","https://api.protontest.alohaeos.com"]
HAPI_EOS_API_ENDPOINTS=["https://proton-testnet.edenia.cloud","https://test.proton.eosusa.news","https://api.testnet.totalproton.tech","https://tn1.protonnz.com"]
HAPI_EOS_API_CHAIN_ID=71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd
HAPI_EOS_BASE_ACCOUNT=baseaccount
HAPI_EOS_BASE_ACCOUNT_PASSWORD=PW...
Expand Down Expand Up @@ -69,7 +69,7 @@ REACT_APP_HASURA_URL=http://localhost:8080/v1/graphql
REACT_APP_EOS_API_NETWORK_NAME=proton-testnet
REACT_APP_EOS_API_NETWORK_LABEL=Proton Testnet
REACT_APP_EOS_API_NETWORK_LOGO=https://antelope.tools/images/proton.png
REACT_APP_EOS_API_HOSTS=["test.proton.eosusa.news","proton-testnet.edenia.cloud","proton-testnet.eosphere.io","api.protontest.alohaeos.com"]
REACT_APP_EOS_API_HOSTS=["test.proton.eosusa.news","proton-testnet.edenia.cloud","api.testnet.totalproton.tech","tn1.protonnz.com"]
REACT_APP_EOS_API_PORT=443
REACT_APP_EOS_API_PROTOCOL=https
REACT_APP_EOS_CHAIN_ID=71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd
Expand Down
4 changes: 2 additions & 2 deletions .env.telostestnet
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ HASURA_GRAPHQL_ACTION_BASE_URL=http://hapi:9090

# hapi
HAPI_EOS_API_NETWORK_NAME=telos
HAPI_EOS_API_ENDPOINTS=["https://testnet.telos.caleos.io","https://telos-testnet.eosphere.io","https://testnet.telosusa.io"]
HAPI_EOS_API_ENDPOINTS=["https://testnet.telos.caleos.io","https://telos-testnet.eosphere.io","https://telostest.api.eosnation.io"]
HAPI_EOS_API_CHAIN_ID=1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f
HAPI_EOS_BASE_ACCOUNT=eosmechatero
HAPI_EOS_BASE_ACCOUNT_PASSWORD=PW...
Expand Down Expand Up @@ -70,7 +70,7 @@ REACT_APP_HASURA_URL=http://localhost:8080/v1/graphql
REACT_APP_EOS_API_NETWORK_NAME=telos-testnet
REACT_APP_EOS_API_NETWORK_LABEL=Telos Testnet
REACT_APP_EOS_API_NETWORK_LOGO=https://antelope.tools/images/telos.png
REACT_APP_EOS_API_HOSTS=["testnet.telos.caleos.io","telos-testnet.eosphere.io","testnet.telosusa.io"]
REACT_APP_EOS_API_HOSTS=["testnet.telos.caleos.io","telos-testnet.eosphere.io","telostest.api.eosnation.io"]
REACT_APP_EOS_API_PORT=443
REACT_APP_EOS_API_PROTOCOL=https
REACT_APP_EOS_CHAIN_ID=1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f
Expand Down
2 changes: 1 addition & 1 deletion .env.ultratestnet
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ REACT_APP_EOS_BP_JSON_ON_CHAIN_SCOPE=producerjson
REACT_APP_SYNC_TOLERANCE_INTERVAL=180000
REACT_APP_TOKEN_SYMBOL=UOS
REACT_APP_NETWORK_URL=[{"label":"Ultra Mainnet","value":"https://antelope.tools","mainnet":true,"pair":"ultra","icon":"ultra","order":1},{"label":"Ultra Testnet","value":"https://ultra-testnet.antelope.tools","mainnet":false,"pair":"ultra","icon":"ultra","order":1}]
REACT_APP_DISABLED_MENU_ITEMS=["/block-producers","/nodes","/missed-blocks","/endpoints","/bpjson","/ricardian-contract","/block-distribution","/nodes-distribution","/cpu-benchmark","/rewards-distribution"]
REACT_APP_DISABLED_MENU_ITEMS=["/block-producers","/nodes","/missed-blocks","/endpoints","/bpjson","/ricardian-contract","/block-distribution","/nodes-distribution","/cpu-benchmark","/rewards-distribution","/endpoints-stats"]
REACT_APP_BLOCK_EXPLORER_URL=https://explorer.testnet.ultra.io/tx/(transaction)
REACT_APP_STATE_HISTORY_ENABLED=false
REACT_APP_GOOGLE_ANALITIC_PAGE_ID=G-E6Y0EC9FT8
Expand Down
4 changes: 2 additions & 2 deletions .env.wax
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ HASURA_GRAPHQL_ACTION_BASE_URL=http://hapi:9090

# hapi
HAPI_EOS_API_NETWORK_NAME=wax
HAPI_EOS_API_ENDPOINTS=["https://wax.eosn.io","https://wax.edenia.cloud","https://wax.api.eosnation.io","https://wax.greymass.com"]
HAPI_EOS_API_ENDPOINTS=["https://wax.api.eosnation.io","https://wax.edenia.cloud","https://wax.api.eosnation.io","https://wax.greymass.com"]
HAPI_EOS_API_CHAIN_ID=1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4
HAPI_EOS_BASE_ACCOUNT=baseaccount
HAPI_EOS_BASE_ACCOUNT_PASSWORD=PW...
Expand Down Expand Up @@ -73,7 +73,7 @@ REACT_APP_HASURA_URL=http://localhost:8080/v1/graphql
REACT_APP_EOS_API_NETWORK_NAME=wax-mainnet
REACT_APP_EOS_API_NETWORK_LABEL=WAX Mainnet
REACT_APP_EOS_API_NETWORK_LOGO=https://antelope.tools/images/wax.jpg
REACT_APP_EOS_API_HOSTS=["wax.eosn.io","wax.edenia.cloud","wax.api.eosnation.io","wax.greymass.com"]
REACT_APP_EOS_API_HOSTS=["wax.api.eosnation.io","wax.edenia.cloud","wax.api.eosnation.io","wax.greymass.com"]
REACT_APP_EOS_API_PORT=443
REACT_APP_EOS_API_PROTOCOL=https
REACT_APP_EOS_CHAIN_ID=1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-libre-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
REACT_APP_SYNC_TOLERANCE_INTERVAL: 180000
REACT_APP_TOKEN_SYMBOL: 'LIBRE'
REACT_APP_NETWORK_URL: '[{"label":"EOS","value":"https://eos.antelope.tools","mainnet":true,"pair":"eos","icon":"eos","order":1},{"label":"Proton","value":"https://proton.antelope.tools","mainnet":true,"pair":"proton","icon":"proton","order":2},{"label":"WAX","value":"https://wax.antelope.tools","mainnet":true,"pair":"wax","icon":"wax","order":3},{"label":"Telos","value":"https://telos.antelope.tools","mainnet":true,"pair":"telos","icon":"telos","order":4},{"label":"Libre","value":"https://libre.antelope.tools","mainnet":true,"pair":"libre","icon":"libre","order":5},{"label":"LACChain EOSIO","value":"https://lacchain.antelope.tools","mainnet":true,"pair":null,"icon":"lacchain","order":6},{"label":"Jungle4 Testnet","value":"https://jungle.antelope.tools","mainnet":false,"pair":"eos","icon":"jungle","order":1},{"label":"Proton Testnet","value":"https://proton-testnet.antelope.tools","mainnet":false,"pair":"proton","icon":"proton","order":2},{"label":"WAX Testnet","value":"https://wax-testnet.antelope.tools","mainnet":false,"pair":"wax","icon":"wax","order":3},{"label":"Telos Testnet","value":"https://telos-testnet.antelope.tools","mainnet":false,"pair":"telos","icon":"telos","order":4},{"label":"Libre Testnet","value":"https://libre-testnet.antelope.tools","mainnet":false,"pair":"libre","icon":"libre","order":5},{"label":"Ultra Testnet","value":"https://ultra-testnet.antelope.tools","mainnet":false,"pair":"ultra","icon":"ultra","order":6}]'
REACT_APP_DISABLED_MENU_ITEMS: '["/cpu-benchmark"]'
REACT_APP_DISABLED_MENU_ITEMS: '[]'
REACT_APP_BLOCK_EXPLORER_URL: 'https://libre-testnet-explorer.edenia.cloud/transaction/(transaction)'
REACT_APP_STATE_HISTORY_ENABLED=: 'true'
REACT_APP_GOOGLE_ANALITIC_PAGE_ID: 'G-E6Y0EC9FT8'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-proton-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
REACT_APP_EOS_API_NETWORK_NAME: 'proton-testnet'
REACT_APP_EOS_API_NETWORK_LABEL: 'Proton Testnet'
REACT_APP_EOS_API_NETWORK_LOGO: 'https://antelope.tools/images/proton.png'
REACT_APP_EOS_API_HOSTS: '[\"test.proton.eosusa.io\",\"proton-testnet.edenia.cloud\",\"proton-testnet.eosphere.io\",\"api.protontest.alohaeos.com\"]'
REACT_APP_EOS_API_HOSTS: '[\"test.proton.eosusa.io\",\"proton-testnet.edenia.cloud\",\"api.testnet.totalproton.tech\",\"tn1.protonnz.com\"]'
REACT_APP_EOS_API_PORT: '443'
REACT_APP_EOS_API_PROTOCOL: 'https'
REACT_APP_EOS_CHAIN_ID: '71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd'
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_DATA: ${{ secrets.POSTGRES_DATA }}
# hapi
HAPI_EOS_API_ENDPOINTS: '["https://proton-testnet.edenia.cloud","https://test.proton.eosusa.io","https://proton-testnet.eosphere.io","https://api.protontest.alohaeos.com"]'
HAPI_EOS_API_ENDPOINTS: '["https://proton-testnet.edenia.cloud","https://test.proton.eosusa.io","https://api.testnet.totalproton.tech","https://tn1.protonnz.com"]'
HAPI_EOS_API_CHAIN_ID: 71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd
HAPI_EOS_BASE_ACCOUNT: ${{ secrets.HAPI_EOS_BASE_ACCOUNT }}
HAPI_EOS_BASE_ACCOUNT_PASSWORD: ${{ secrets.HAPI_EOS_BASE_ACCOUNT_PASSWORD }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-proton.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
REACT_APP_EOS_API_NETWORK_NAME: 'proton'
REACT_APP_EOS_API_NETWORK_LABEL: 'Proton Mainnet'
REACT_APP_EOS_API_NETWORK_LOGO: 'https://antelope.tools/images/proton.png'
REACT_APP_EOS_API_HOSTS: '[\"proton.edenia.cloud\",\"proton.eosusa.io\",\"proton.greymass.com\",\"proton.eosphere.io\"]'
REACT_APP_EOS_API_HOSTS: '[\"proton.edenia.cloud\",\"proton.eosusa.io\",\"proton.greymass.com\",\"proton.eosargentina.io\"]'
REACT_APP_EOS_API_PORT: '443'
REACT_APP_EOS_API_PROTOCOL: 'https'
REACT_APP_EOS_CHAIN_ID: '384da888112027f0321850a169f737c33e53b388aad48b5adace4bab97f437e0'
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_DATA: ${{ secrets.POSTGRES_DATA }}
# hapi
HAPI_EOS_API_ENDPOINTS: '["https://proton.edenia.cloud","https://proton.eosusa.news","https://proton.greymass.com","https://proton.eosphere.io"]'
HAPI_EOS_API_ENDPOINTS: '["https://proton.edenia.cloud","https://proton.eosusa.io","https://proton.greymass.com","https://proton.eosargentina.io"]'
HAPI_EOS_API_CHAIN_ID: 384da888112027f0321850a169f737c33e53b388aad48b5adace4bab97f437e0
HAPI_EOS_BASE_ACCOUNT: ${{ secrets.HAPI_EOS_BASE_ACCOUNT }}
HAPI_EOS_BASE_ACCOUNT_PASSWORD: ${{ secrets.HAPI_EOS_BASE_ACCOUNT_PASSWORD }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-telos-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
REACT_APP_EOS_API_NETWORK_NAME: 'telos-testnet'
REACT_APP_EOS_API_NETWORK_LABEL: 'Telos Testnet'
REACT_APP_EOS_API_NETWORK_LOGO: 'https://antelope.tools/images/telos.png'
REACT_APP_EOS_API_HOSTS: '[\"testnet.telos.caleos.io\",\"telos-testnet.eosphere.io\",\"testnet.telosusa.io\"]'
REACT_APP_EOS_API_HOSTS: '[\"testnet.telos.caleos.io\",\"telos-testnet.eosphere.io\",\"telostest.api.eosnation.io\"]'
REACT_APP_EOS_API_PORT: '443'
REACT_APP_EOS_API_PROTOCOL: 'https'
REACT_APP_EOS_CHAIN_ID: '1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f'
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
POSTGRES_DATA: ${{ secrets.POSTGRES_DATA }}
# hapi
HAPI_EOS_API_NETWORK_NAME: telos
HAPI_EOS_API_ENDPOINTS: '["https://testnet.telos.caleos.io","https://telos-testnet.eosphere.io","https://testnet.telosusa.io"]'
HAPI_EOS_API_ENDPOINTS: '["https://testnet.telos.caleos.io","https://telos-testnet.eosphere.io","https://telostest.api.eosnation.io"]'
HAPI_EOS_API_CHAIN_ID: 1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f
HAPI_EOS_BASE_ACCOUNT: ${{ secrets.HAPI_EOS_BASE_ACCOUNT }}
HAPI_EOS_BASE_ACCOUNT_PASSWORD: ${{ secrets.HAPI_EOS_BASE_ACCOUNT_PASSWORD }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-ultra-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
REACT_APP_SYNC_TOLERANCE_INTERVAL: 180000
REACT_APP_TOKEN_SYMBOL: 'UOS'
REACT_APP_NETWORK_URL: '[{"label":"EOS","value":"https://eos.antelope.tools","mainnet":true,"pair":"eos","icon":"eos","order":1},{"label":"Proton","value":"https://proton.antelope.tools","mainnet":true,"pair":"proton","icon":"proton","order":2},{"label":"WAX","value":"https://wax.antelope.tools","mainnet":true,"pair":"wax","icon":"wax","order":3},{"label":"Telos","value":"https://telos.antelope.tools","mainnet":true,"pair":"telos","icon":"telos","order":4},{"label":"Libre","value":"https://libre.antelope.tools","mainnet":true,"pair":"libre","icon":"libre","order":5},{"label":"LACChain EOSIO","value":"https://lacchain.antelope.tools","mainnet":true,"pair":null,"icon":"lacchain","order":6},{"label":"Jungle4 Testnet","value":"https://jungle.antelope.tools","mainnet":false,"pair":"eos","icon":"jungle","order":1},{"label":"Proton Testnet","value":"https://proton-testnet.antelope.tools","mainnet":false,"pair":"proton","icon":"proton","order":2},{"label":"WAX Testnet","value":"https://wax-testnet.antelope.tools","mainnet":false,"pair":"wax","icon":"wax","order":3},{"label":"Telos Testnet","value":"https://telos-testnet.antelope.tools","mainnet":false,"pair":"telos","icon":"telos","order":4},{"label":"Libre Testnet","value":"https://libre-testnet.antelope.tools","mainnet":false,"pair":"libre","icon":"libre","order":5},{"label":"Ultra Testnet","value":"https://ultra-testnet.antelope.tools","mainnet":false,"pair":"ultra","icon":"ultra","order":6}]'
REACT_APP_DISABLED_MENU_ITEMS: '["/block-producers","/nodes","/missed-blocks","/endpoints","/bpjson","/ricardian-contract","/block-distribution","/nodes-distribution","/cpu-benchmark","/rewards-distribution","/undiscoverable-bps"]'
REACT_APP_DISABLED_MENU_ITEMS: '["/block-producers","/nodes","/missed-blocks","/endpoints","/bpjson","/ricardian-contract","/block-distribution","/nodes-distribution","/cpu-benchmark","/rewards-distribution","/undiscoverable-bps","/endpoints-stats"]'
REACT_APP_BLOCK_EXPLORER_URL: 'https://explorer.testnet.ultra.io/tx/(transaction)'
REACT_APP_STATE_HISTORY_ENABLED: 'false'
REACT_APP_GOOGLE_ANALITIC_PAGE_ID: 'G-E6Y0EC9FT8'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-wax.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
REACT_APP_EOS_API_NETWORK_NAME: 'wax'
REACT_APP_EOS_API_NETWORK_LABEL: 'WAX Mainnet'
REACT_APP_EOS_API_NETWORK_LOGO: 'https://antelope.tools/images/wax.jpg'
REACT_APP_EOS_API_HOSTS: '[\"wax.eosn.io\",\"wax.edenia.cloud\",\"wax.api.eosnation.io\",\"wax.greymass.com\"]'
REACT_APP_EOS_API_HOSTS: '[\"wax.api.eosnation.io\",\"wax.edenia.cloud\",\"wax.api.eosnation.io\",\"wax.greymass.com\"]'
REACT_APP_EOS_API_PORT: '443'
REACT_APP_EOS_API_PROTOCOL: 'https'
REACT_APP_EOS_CHAIN_ID: '1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4'
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
POSTGRES_DATA: ${{ secrets.POSTGRES_DATA }}
# hapi
HAPI_EOS_API_NETWORK_NAME: wax
HAPI_EOS_API_ENDPOINTS: '["https://wax.eosn.io","https://wax.edenia.cloud","https://wax.api.eosnation.io","https://wax.greymass.com"]'
HAPI_EOS_API_ENDPOINTS: '["https://wax.api.eosnation.io","https://wax.edenia.cloud","https://wax.api.eosnation.io","https://wax.greymass.com"]'
HAPI_EOS_API_CHAIN_ID: 1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4
HAPI_EOS_BASE_ACCOUNT: ${{ secrets.HAPI_EOS_BASE_ACCOUNT }}
HAPI_EOS_BASE_ACCOUNT_PASSWORD: ${{ secrets.HAPI_EOS_BASE_ACCOUNT_PASSWORD }}
Expand Down
6 changes: 6 additions & 0 deletions hapi/src/config/eos.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ module.exports = {
telos: 'telos',
wax: 'wax'
},
healthCheckAPIs: [
{ name: 'chain-api', api: '/v1/chain/get_info' },
{ name: 'atomic-assets-api', api: '/atomicassets/v1/config' },
{ name: 'hyperion-v2', api: '/v2/health' },
{ name: 'light-api', api: '/api/status' }
],
rewardsToken: process.env.HAPI_REWARDS_TOKEN,
eosRateUrl: process.env.HAPI_EOSRATE_GET_STATS_URL,
eosRateUser: process.env.HAPI_EOSRATE_GET_STATS_USER,
Expand Down
113 changes: 113 additions & 0 deletions hapi/src/services/health-check-history.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
const { hasuraUtil } = require('../utils')

const newEndpointsHealthHistory = async (endpoints, payload) => {
const mutation = `
mutation insert($payload: health_check_history_insert_input!,$endpoints: [endpoints_check_history_insert_input!]!) {
insert_health_check_history_one(object: $payload, on_conflict: {constraint: health_check_history_pkey, update_columns: [total_checks, date]}) {
id
}
insert_endpoints_check_history(objects: $endpoints, on_conflict: {constraint: endpoints_check_history_pkey, update_columns: [producer_id, value, successful_checks, sum_total_time, date]}) {
affected_rows
}
}
`

endpoints = endpoints.map(endpoint => ({
successful_checks: endpoint.isWorking,
sum_total_time: endpoint.time,
value: endpoint.value,
producer_id: endpoint.producer_id,
date: payload.date
}))

await hasuraUtil.request(mutation, { payload, endpoints })
}

const updateEndpointsHealthHistory = async (endpoints, date) => {
const mutation = `
mutation insert($date: date!,$updates: [endpoints_check_history_updates!]!) {
update_health_check_history(where: {date: {_eq: $date}}, _inc: {total_checks: 1}) {
affected_rows
}
update_endpoints_check_history_many(updates: $updates) {
affected_rows
}
}
`
const updates = endpoints.map(endpoint => ({
where: {
_and: [{ value: { _eq: endpoint.value } }, { date: { _eq: date } }]
},
_inc: {
successful_checks: endpoint.isWorking,
sum_total_time: endpoint.time
}
}))

await hasuraUtil.request(mutation, { date, updates })
}

const clearEndpointsHealthHistory = async (limit) => {
const date = new Date()

date.setHours(0, 0, 0, 0)
date.setDate(date.getDate() - limit)

const mutation = `
mutation clear($date: date){
delete_endpoints_check_history(where: {date: {_eq: $date}}){
affected_rows
}
}
`

await hasuraUtil.request(mutation, { date })
}

const saveHealthRegister = async endpoints => {
const today = new Date()

today.setHours(0, 0, 0, 0)

const query = `
query($today: date){
history: health_check_history_aggregate{
aggregate{
count
}
}
older: health_check_history(limit: 1, order_by: {date: asc}){
id
}
current: health_check_history(limit: 1, where: {date: {_eq: $today}}){
id
}
}`

const limit = 30
const {
older,
current,
history: {
aggregate: { count }
}
} = await hasuraUtil.request(query, { today })

if (current?.length) {
await updateEndpointsHealthHistory(endpoints, today)
} else {
const payload = { date: today, total_checks: 1 }

if (count + 1 > limit) {
payload.id = older[0].id
}

await newEndpointsHealthHistory(endpoints, payload)
await clearEndpointsHealthHistory(limit)
}
}

module.exports = {
saveHealthRegister,
clearEndpointsHealthHistory
}
2 changes: 2 additions & 0 deletions hapi/src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const cpuService = require('./cpu.service')
const missedBlocksService = require('./missed-blocks.service')
const producerService = require('./producer.service')
const nodeService = require('./node.service')
const healthCheckHistoryService = require('./health-check-history.service')
const settingService = require('./setting.service')
const stateHistoryPluginService = require('./state-history-plugin.service')
const statsService = require('./stats.service')
Expand All @@ -14,6 +15,7 @@ module.exports = {
missedBlocksService,
producerService,
nodeService,
healthCheckHistoryService,
settingService,
stateHistoryPluginService,
statsService,
Expand Down
10 changes: 3 additions & 7 deletions hapi/src/services/node.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ const updateEndpointInfo = async endpoint => {
}
`

const { nodeInfo, ...response } = await producerUtil.getNodeInfo(
endpoint.value
)

await hasuraUtil.request(updateMutation, {
id: endpoint.id,
response,
head_block_time: nodeInfo?.head_block_time || null,
updated_at: new Date()
response: endpoint?.response || {},
head_block_time: endpoint?.head_block_time || null,
updated_at: endpoint.updated_at
})
}

Expand Down
Loading

0 comments on commit 666195b

Please sign in to comment.