Skip to content

Commit

Permalink
update name/path of api route, send nothing to report message (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggnine-jito authored Jan 8, 2024
1 parent a6242c4 commit 1fdc8c4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { withSentry } from '@sentry/nextjs'
import { runNotifier } from '../../scripts/governance-notifier'

export default async function (req, res) {
console.log('req?.headers?.authorization')
console.log(req?.headers?.authorization)
if (req?.headers?.authorization !== `Bearer ${process.env.CRON_SECRET}`) {
return res.status(401).send('Unauthorized')
}

async function handler(req, res) {
// if (req?.headers?.authorization !== `Bearer ${process.env.CRON_SECRET}`) {
// return res.status(401).send('Unauthorized')
// }
try {
await runNotifier()
res.status(200).send('Notifier executed successfully')
Expand All @@ -15,3 +13,5 @@ export default async function (req, res) {
res.status(500).send('Error executing notifier')
}
}

export default withSentry(handler)
13 changes: 11 additions & 2 deletions scripts/governance-notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function errorWrapper() {

export async function runNotifier() {
const REALM = 'Jito'
console.log("starting governance notifier")
console.log('Starting governance notifier')
const connectionContext = getConnectionContext('mainnet')
const realmInfo = await getCertifiedRealmInfo(REALM, connectionContext)

Expand All @@ -43,6 +43,7 @@ export async function runNotifier() {
)

const governancesMap = accountsToPubkeyMap(governances)
let webhookTriggered = false

console.log(`- getting all proposals for all governances`)
const proposalsByGovernance = await Promise.all(
Expand Down Expand Up @@ -125,6 +126,7 @@ export async function runNotifier() {
console.log(msg)
if (process.env.WEBHOOK_URL) {
axios.post(process.env.WEBHOOK_URL, { content: msg })
webhookTriggered = true
}
}
countClosed++
Expand Down Expand Up @@ -159,6 +161,7 @@ export async function runNotifier() {
console.log(msg)
if (process.env.WEBHOOK_URL) {
axios.post(process.env.WEBHOOK_URL, { content: msg })
webhookTriggered = true
}
}
// note that these could also include those in finalizing state, but this is just for logging
Expand Down Expand Up @@ -196,13 +199,19 @@ export async function runNotifier() {
console.log(msg)
if (process.env.WEBHOOK_URL) {
axios.post(process.env.WEBHOOK_URL, { content: msg })
webhookTriggered = true
}
}
}
}

if (!webhookTriggered && process.env.WEBHOOK_URL) {
axios.post(process.env.WEBHOOK_URL, { content: 'Nothing to Report' })
}

console.log(
`-- countOpenForVotingSinceSomeTime: ${countOpenForVotingSinceSomeTime}, countJustOpenedForVoting: ${countJustOpenedForVoting}, countVotingNotStartedYet: ${countVotingNotStartedYet}, countClosed: ${countClosed}, countCancelled: ${countCancelled}`
)
}

errorWrapper()
errorWrapper()

0 comments on commit 1fdc8c4

Please sign in to comment.