1
0
mirror of synced 2025-12-23 03:44:00 -05:00
Files
docs/script/ping-staging-apps.js
Kevin Heis 8a56437c93 Pretty format (#20352)
* Update prettier flow to include JS

* Run prettier

* ...run prettier
2021-07-14 14:35:01 -07:00

41 lines
1012 B
JavaScript
Executable File

#!/usr/bin/env node
import xDotenv from 'dotenv'
import assert from 'assert'
import got from 'got'
import { chain } from 'lodash-es'
import chalk from 'chalk'
import Heroku from 'heroku-client'
// [start-readme]
//
// This script finds all Heroku staging apps and pings them to make sure they're always "warmed" and responsive to requests.
//
// [end-readme]
xDotenv.config()
assert(process.env.HEROKU_API_TOKEN)
const heroku = new Heroku({ token: process.env.HEROKU_API_TOKEN })
main()
async function main() {
const apps = chain(await heroku.get('/apps'))
.orderBy('name')
.value()
async function ping(app) {
// ?warmup param has no effect but makes it easier to find these requests in the logs
const url = `https://${app.name}.herokuapp.com/en?warmup`
try {
const response = await got(url)
console.log(chalk.green(url, response.statusCode))
} catch (error) {
console.log(chalk.red(url, error.response.statusCode))
}
}
Promise.all(apps.map(ping))
}