Skip to content

Commit

Permalink
fix daily aqi jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyen-Duc-Khai committed Jan 19, 2024
1 parent 5a0006c commit 2ef6150
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 59 deletions.
54 changes: 0 additions & 54 deletions backend/src/jobs/definitions/getHourlyAqi.js

This file was deleted.

3 changes: 1 addition & 2 deletions backend/src/jobs/definitions/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const { retrieveDailyAqi } = require("./retrieveDailyAqi");
const { getHourlyAqi } = require("./getHourlyAqi");
const logger = require("../../config/logger");

let definitions = [retrieveDailyAqi, getHourlyAqi];
let definitions = [retrieveDailyAqi];

const loadDefinitions = async (agenda) => {
try {
Expand Down
8 changes: 5 additions & 3 deletions backend/src/jobs/definitions/retrieveDailyAqi.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const retrieveDailyAqi = async (agenda) => {
.toISOString()
.replace(/T(.+)/g, "T00:00:00.000Z");

logger.info(`Get AQI for ${offsetNextDay}`);

let hourlyAqi = await AirQualityModel.aggregate([
{
$addFields: {
Expand Down Expand Up @@ -56,7 +58,7 @@ const retrieveDailyAqi = async (agenda) => {
},
]).exec();

console.log(hourlyAqi);
logger.info(JSON.stringify(hourlyAqi));

hourlyAqi = hourlyAqi.map((x) => {
return {
Expand All @@ -65,7 +67,7 @@ const retrieveDailyAqi = async (agenda) => {
};
});

console.log(hourlyAqi);
logger.info(JSON.stringify(hourlyAqi));

const compositeAqiObject = hourlyAqi.reduce((prev, curr) =>
prev.aqi > curr.aqi ? prev : curr
Expand All @@ -76,7 +78,7 @@ const retrieveDailyAqi = async (agenda) => {
date: compositeAqiObject.dateTime.substring(0, 10),
};

console.log(requestBody);
logger.info(JSON.stringify(requestBody));

await axios({
method: "post",
Expand Down

0 comments on commit 2ef6150

Please sign in to comment.