Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

ping-staging-apps.js 1017 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  1. #!/usr/bin/env node
  2. // [start-readme]
  3. //
  4. // This script finds all Heroku staging apps and pings them to make sure they're always "warmed" and responsive to requests.
  5. //
  6. // [end-readme]
  7. require('dotenv').config()
  8. const assert = require('assert')
  9. const got = require('got')
  10. assert(process.env.HEROKU_API_TOKEN)
  11. const { chain } = require('lodash')
  12. const chalk = require('chalk')
  13. const Heroku = require('heroku-client')
  14. const heroku = new Heroku({ token: process.env.HEROKU_API_TOKEN })
  15. main()
  16. async function main () {
  17. const apps = chain(await heroku.get('/apps'))
  18. .orderBy('name')
  19. .value()
  20. async function ping (app) {
  21. // ?warmup param has no effect but makes it easier to find these requests in the logs
  22. const url = `https://${app.name}.herokuapp.com/en?warmup`
  23. try {
  24. const response = await got(url)
  25. console.log(chalk.green(url, response.statusCode))
  26. } catch (error) {
  27. console.log(chalk.red(url, error.response.statusCode))
  28. }
  29. }
  30. Promise.all(apps.map(ping))
  31. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...