diff --git a/pages/api/governance-notifier.ts b/pages/api/governance-notifier.api.ts similarity index 50% rename from pages/api/governance-notifier.ts rename to pages/api/governance-notifier.api.ts index 4a49837bdd..b287be491c 100644 --- a/pages/api/governance-notifier.ts +++ b/pages/api/governance-notifier.api.ts @@ -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') @@ -15,3 +13,5 @@ export default async function (req, res) { res.status(500).send('Error executing notifier') } } + +export default withSentry(handler) diff --git a/scripts/governance-notifier.ts b/scripts/governance-notifier.ts index 89b6654eb5..4ffd8d511f 100644 --- a/scripts/governance-notifier.ts +++ b/scripts/governance-notifier.ts @@ -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) @@ -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( @@ -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++ @@ -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 @@ -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() \ No newline at end of file +errorWrapper()