Skip to content

Commit

Permalink
clean up shutdown procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
RebootJeff committed Feb 27, 2021
1 parent 2c3cf46 commit 93ddb8a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const startChecking = async (browser) => {
const page = await browser.newPage()

while (true) {
console.log('ℹ You can exit by hitting CTRL+C ...but it may take a minute to fully exit.')
console.log('ℹ You can exit by hitting CTRL+C ...but it may take ~10sec to fully exit.')

await checkAllSites(page)

Expand Down
15 changes: 3 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@ import {
HIDE_BROWSER, BROWSER_SIZE,
} from '../privateConfig.js'

let browser

// TODO: On Windows, there is a long pause between the browser closing and "Closing browser..."
// getting logged. Somehow CTRL+C stops Puppeteer browser before this function runs.
// And why is there such a long pause?
// TODO: On Windows, there is a long pause between the browser closing and exiting the process.
const shutDown = async (code = 0) => {
if (browser) {
logger.log('🏁 Closing browser...')
await browser.close() // TODO: Node doesn't seem to wait for this.
console.log('why doesn\'t this show up?')
}
process.exit(code)
}

Expand All @@ -33,14 +24,14 @@ process.on('exit', () => {
const start = async () => {
logger.log('🚦 Launching browser...')
const { height, width } = BROWSER_SIZE
browser = await puppeteer.launch({
const browser = await puppeteer.launch({
headless: HIDE_BROWSER,
defaultViewport: { width, height },
args: [`--window-size=${width},${height}`]
})

try {
startChecking(browser)
await startChecking(browser)
} catch (err) {
logger.error('💥 App failure:', err)
await shutDown(1)
Expand Down

0 comments on commit 93ddb8a

Please sign in to comment.