-
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.
- Loading branch information
1 parent
f367100
commit a999864
Showing
18 changed files
with
325 additions
and
128 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 was deleted.
Oops, something went wrong.
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,54 @@ | ||
const { aqiApiToken, predictionServiceUrl } = require("../../config/config"); | ||
const axios = require("axios"); | ||
const logger = require("../../config/logger"); | ||
const HourlyAQIModel = require("../../models/HourlyAQI"); | ||
|
||
const AQI_URL = "http://api.waqi.info"; | ||
|
||
const getHourlyAqi = async (agenda) => { | ||
try { | ||
// define(jobName, fn, [options]) | ||
agenda.define( | ||
"getHourlyAqi", | ||
async function (job, done) { | ||
try { | ||
var response = await axios({ | ||
method: "get", | ||
url: `${AQI_URL}/feed/@1583/?token=${aqiApiToken}`, | ||
}); | ||
|
||
response = response.data; | ||
|
||
const aqi = await HourlyAQIModel.findOne({ | ||
dateTime: response.data.time.iso, | ||
}); | ||
|
||
logger.info( | ||
`New AQI retrieved for date ${response.data.time.iso} from ${AQI_URL}: ${response.data.aqi}` | ||
); | ||
|
||
if (!aqi) { | ||
await HourlyAQIModel.create({ | ||
aqi: response.data.aqi, | ||
dateTime: response.data.time.iso, | ||
}); | ||
} | ||
|
||
done(); | ||
} catch (error) { | ||
console.error(error); | ||
|
||
logger.error( | ||
"Failed to update new daily aqi in job [agenda.retrieveDailyAqi] : " + | ||
error.message | ||
); | ||
} | ||
}, | ||
{ priority: "highest", concurrency: 20 } | ||
); | ||
} catch (error) { | ||
logger.error("Error in job [agenda.retrieveDailyAqi] : " + error); | ||
} | ||
}; | ||
|
||
module.exports = { getHourlyAqi }; |
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
Oops, something went wrong.