-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust cache warming schedule; add back crawler
- Loading branch information
1 parent
290e6ea
commit 986b20e
Showing
4 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// This script was originally written to force cache warming, but with that | ||
// code having been refactored am now using it for performance testing. | ||
const dbAsync = require('./db/db-async') | ||
const { ARDENT_API_HOSTNAME } = require('./consts') | ||
|
||
module.exports = async (debug = true) => { | ||
console.time('Crawl commodities') | ||
try { | ||
const commodities = await dbAsync.all('SELECT DISTINCT(commodityName) FROM commodities') | ||
if (debug === true) console.log(`Warming cache for ${ARDENT_API_HOSTNAME}`) | ||
for (let i = 0; i < commodities.length; i++) { | ||
const { commodityName } = commodities[i] | ||
const url = `https://${ARDENT_API_HOSTNAME}/v1/commodity/name/${commodityName}/imports` | ||
if (debug === true) console.time(`${i+1} of ${commodities.length} ${commodityName}`) | ||
const res = await fetch(url) | ||
if (!res.ok) console.error(`Crawler error fetching: ${url}`) | ||
if (debug === true) console.timeEnd(`${i+1} of ${commodities.length} ${commodityName}`) | ||
} | ||
} catch (e) { | ||
return console.error('Crawler failed:', e) | ||
} | ||
console.timeEnd('Crawl commodities') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const crawler = require('../lib/crawler') | ||
;(async () => { | ||
await crawler() | ||
process.exit() | ||
})() |