Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update name/path of api route, send nothing to report message #9

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading