lighthouse
This commit is contained in:
17
api/jobs/lighthouse.js
Normal file
17
api/jobs/lighthouse.js
Normal file
@@ -0,0 +1,17 @@
|
||||
var { setUpQuery, calculateAverageDynamically, run } = require("../hooks/lib/utils")
|
||||
;(function () {
|
||||
console.log("Running lighthouse job")
|
||||
let subPaths = context.db.find("lighthouseSubpath")
|
||||
let urls = []
|
||||
for (let i = 0; i < subPaths.length; i++) {
|
||||
urls.push(setUpQuery(subPaths[i].lighthouseSubpath))
|
||||
}
|
||||
let dbObjs = []
|
||||
urls.forEach((url) => {
|
||||
console.log("URL:", url)
|
||||
dbObjs.push(run(url))
|
||||
})
|
||||
let dbObject = calculateAverageDynamically(dbObjs)
|
||||
dbObject.analyzedPaths = [...subPaths].map((subPath) => subPath.lighthouseSubpath)
|
||||
context.db.create("lighthouse", dbObject)
|
||||
})()
|
||||
@@ -1,9 +0,0 @@
|
||||
function requestTemperature() {
|
||||
let response = context.http.fetch(
|
||||
"https://api.openweathermap.org/data/2.5/weather?lat=50.98&lon=11.03&appid=21fa3d5930956682000f7a2db5f357c0"
|
||||
)
|
||||
let data = response.body.json()
|
||||
let temperatureEntries = context.db.find("temperature")
|
||||
context.db.update("temperature", temperatureEntries[0].id, { temperature: data.main.temp - 273.15 })
|
||||
}
|
||||
requestTemperature()
|
||||
Reference in New Issue
Block a user