Skip to content

Commit

Permalink
feat: add heartbeat to cron jobs (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Apr 26, 2022
1 parent 234ae36 commit aa42e06
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/cron-denylist.yml
Expand Up @@ -31,3 +31,7 @@ jobs:
env:
CF_API_TOKEN: ${{ secrets.CF_GATEWAY_TOKEN }}
run: node packages/edge-gateway/scripts/cli.js denylist sync --env ${{ matrix.env }}

- name: Heartbeat
if: ${{ success() }}
run: node packages/edge-gateway/scripts/cli.js heartbeat --token ${{ secrets.OPSGENIE_KEY }} --name cron-nftstoragelink-denylist
5 changes: 5 additions & 0 deletions packages/edge-gateway/scripts/cli.js
Expand Up @@ -12,6 +12,7 @@ import pWaitFor from 'p-wait-for'
import { create } from 'ipfs-http-client'
import globSource from 'ipfs-utils/src/files/glob-source.js'
import { denylistSyncCmd, denylistAddCmd } from './denylist.js'
import { heartbeatCmd } from './heartbeat.js'

const IPFS_API_URL = 'http://127.0.0.1:9089'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
Expand All @@ -31,6 +32,10 @@ prog
.option('--start', 'Start docker container', false)
.option('--stop', 'Stop and clean all dockers artifacts', false)
.action(ipfsCmd)
.command('heartbeat', 'Ping opsgenie heartbeat')
.option('--token', 'Opsgenie Token')
.option('--name', 'Heartbeat Name')
.action(heartbeatCmd)
.command('denylist sync')
.describe('Sync the gateway deny list with various sources.')
.option('--env', 'Wrangler environment to use.', 'dev')
Expand Down
14 changes: 14 additions & 0 deletions packages/edge-gateway/scripts/heartbeat.js
@@ -0,0 +1,14 @@
import { fetch } from '@web-std/fetch'

export async function heartbeatCmd(opts) {
try {
await fetch(`https://api.opsgenie.com/v2/heartbeats/${opts.name}/ping`, {
headers: {
Authorization: `GenieKey ${opts.token}`,
},
})
} catch (err) {
console.error(err)
process.exit(1)
}
}

0 comments on commit aa42e06

Please sign in to comment.