send errors to webhook
This commit is contained in:
parent
19198bb59a
commit
8b805a4961
|
@ -15,6 +15,7 @@
|
|||
"dependencies": {
|
||||
"@ltd/j-toml": "^1.6.0",
|
||||
"@solana/web3.js": "^0.90.5",
|
||||
"axios": "^0.21.1",
|
||||
"borsh": "https://github.com/defactojob/borsh-js#field-mapper",
|
||||
"buffer-layout": "^1.2.0",
|
||||
"commander": "^6.2.0",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import WebSocket from 'ws'
|
||||
import ReconnectingWebSocket from 'reconnecting-websocket'
|
||||
import EventEmitter from "events"
|
||||
import { eventsIter, median } from "./utils"
|
||||
import { eventsIter, median, notify } from "./utils"
|
||||
|
||||
import { log } from "./log"
|
||||
import winston from "winston"
|
||||
|
@ -40,7 +40,7 @@ export abstract class PriceFeed {
|
|||
this.connected = new Promise<void>((resolve) => {
|
||||
const conn = new ReconnectingWebSocket(this.baseurl, [], { WebSocket })
|
||||
conn.addEventListener("open", () => {
|
||||
this.log.debug("connected")
|
||||
notify(`socket ${this.baseurl}: open`)
|
||||
|
||||
this.conn = conn
|
||||
|
||||
|
@ -52,11 +52,11 @@ export abstract class PriceFeed {
|
|||
})
|
||||
|
||||
conn.addEventListener("close", () => {
|
||||
console.log(`socket ${this.baseurl} closed`)
|
||||
notify(`socket ${this.baseurl}: closed`)
|
||||
})
|
||||
|
||||
conn.addEventListener("error", (e) => {
|
||||
console.log(`socket ${this.baseurl} error: ${e}`)
|
||||
notify(`socket ${this.baseurl}: error=${e}`)
|
||||
})
|
||||
|
||||
conn.addEventListener("message", (msg) => {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import axios from 'axios';
|
||||
import { AccountInfo, Connection, PublicKey } from "@solana/web3.js"
|
||||
import EventEmitter from "events"
|
||||
|
||||
|
@ -34,6 +35,12 @@ export function getMedian(submissions: number[]): number {
|
|||
}
|
||||
}
|
||||
|
||||
export function notify(content) {
|
||||
if (process.env.WEBHOOK_URL) {
|
||||
axios.post(process.env.WEBHOOK_URL, {content});
|
||||
}
|
||||
}
|
||||
|
||||
export function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
|
|
12
yarn.lock
12
yarn.lock
|
@ -214,6 +214,13 @@ async@^3.1.0:
|
|||
resolved "https://registry.yarnpkg.com/async/-/async-3.2.0.tgz#b3a2685c5ebb641d3de02d161002c60fc9f85720"
|
||||
integrity sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==
|
||||
|
||||
axios@^0.21.1:
|
||||
version "0.21.1"
|
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
|
||||
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
|
||||
dependencies:
|
||||
follow-redirects "^1.10.0"
|
||||
|
||||
balanced-match@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
|
||||
|
@ -815,6 +822,11 @@ fn.name@1.x.x:
|
|||
resolved "https://registry.yarnpkg.com/fn.name/-/fn.name-1.1.0.tgz#26cad8017967aea8731bc42961d04a3d5988accc"
|
||||
integrity sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==
|
||||
|
||||
follow-redirects@^1.10.0:
|
||||
version "1.13.3"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.3.tgz#e5598ad50174c1bc4e872301e82ac2cd97f90267"
|
||||
integrity sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==
|
||||
|
||||
fs-extra@1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-1.0.0.tgz#cd3ce5f7e7cb6145883fcae3191e9877f8587950"
|
||||
|
|
Loading…
Reference in New Issue