diff --git a/package.json b/package.json index e2fe5c5..0a1bb80 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "dependencies": { "@blockworks-foundation/mango-client": "^3.0.12", "@solana/web3.js": "^1.18.0", + "axios": "^0.21.1", "cors": "^2.8.5", "dotenv": "^8.2.0", "express": "^4.17.1", diff --git a/src/collectStats.ts b/src/collectStats.ts index 148ffe5..1d2ff1a 100644 --- a/src/collectStats.ts +++ b/src/collectStats.ts @@ -14,6 +14,7 @@ import { } from "@blockworks-foundation/mango-client" import PerpMarketStats from "../models/perp_market_stats" import SpotMarketStats from "../models/spot_market_stats" +import notify from "./notify" const CLUSTER_URLS = [ { @@ -81,6 +82,7 @@ async function fetchSpotStats() { await SpotMarketStats.bulkCreate(spotMarketStats) console.log("spot stats inserted") } catch (err) { + notify(`mango-stats-v3 perp stats ERROR: ${err}`) console.log("failed to insert spot stats", `${err}`) } finally { setTimeout(fetchSpotStats, SPOT_INTERVAL) @@ -115,12 +117,14 @@ async function fetchPerpStats() { console.log("perp stats inserted") } catch (err) { console.log("failed to insert perp stats", `${err}`) + notify(`mango-stats-v3 spot stats ERROR: ${err}`) } finally { setTimeout(fetchPerpStats, PERP_INTERVAL) } } async function main() { + notify("mango-stats-v3 restarting") fetchPerpStats() fetchSpotStats() } diff --git a/src/notify.ts b/src/notify.ts new file mode 100644 index 0000000..5b36020 --- /dev/null +++ b/src/notify.ts @@ -0,0 +1,13 @@ +import axios from "axios" + +export default function notify(content: string) { + if (process.env.WEBHOOK_URL) { + try { + axios.post(process.env.WEBHOOK_URL, { content }) + } catch (e) { + console.error(`could not notify webhook: ${content}`) + } + } else { + console.warn(content) + } +} diff --git a/yarn.lock b/yarn.lock index 33c8b94..daf6446 100644 --- a/yarn.lock +++ b/yarn.lock @@ -557,6 +557,13 @@ astral-regex@^2.0.0: resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31" integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ== +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.2" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" @@ -639,9 +646,9 @@ borsh@^0.4.0: bs58 "^4.0.0" text-encoding-utf-8 "^1.0.2" -"borsh@git+https://github.com/defactojob/borsh-js.git#field-mapper": +"borsh@https://github.com/defactojob/borsh-js#field-mapper": version "0.3.1" - resolved "git+https://github.com/defactojob/borsh-js.git#33a0d24af281112c0a48efb3fa503f3212443de9" + resolved "https://github.com/defactojob/borsh-js#33a0d24af281112c0a48efb3fa503f3212443de9" dependencies: "@types/bn.js" "^4.11.5" bn.js "^5.0.0" @@ -1425,6 +1432,11 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469" integrity sha512-zAoAQiudy+r5SvnSw3KJy5os/oRJYHzrzja/tBDqrZtNhUw8bt6y8OBzMWcjWr+8liV8Eb6yOhw8WZ7VFZ5ZzA== +follow-redirects@^1.10.0: + version "1.14.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.2.tgz#cecb825047c00f5e66b142f90fed4f515dec789b" + integrity sha512-yLR6WaE2lbF0x4K2qE2p9PEXKLDjUjnR/xmjS3wHAYxtlsI9MLLBJUZirAHKzUZDGLxje7w/cXR49WOUo4rbsA== + forwarded@~0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84"