Skip to content

Commit

Permalink
Merge pull request #2436 from airqo-platform/staging
Browse files Browse the repository at this point in the history
move to production
  • Loading branch information
Baalmart authored Nov 5, 2023
2 parents 58e0f4e + 0517d92 commit 0b88eec
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 11 deletions.
2 changes: 1 addition & 1 deletion k8s/airflow/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ images:
repositories:
initContainer: eu.gcr.io/airqo-250220/airqo-apache-airflow-xcom
containers: eu.gcr.io/airqo-250220/airqo-apache-airflow
tag: prod-6ea06af8-1699219770
tag: prod-58e0f4e4-1699224315
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/analytics/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ images:
celeryWorker: eu.gcr.io/airqo-250220/airqo-analytics-celery-worker
reportJob: eu.gcr.io/airqo-250220/airqo-analytics-report-job
devicesSummaryJob: eu.gcr.io/airqo-250220/airqo-analytics-devices-summary-job
tag: prod-6ea06af8-1699219770
tag: prod-58e0f4e4-1699224315
api:
name: airqo-analytics-api
label: analytics-api
Expand Down
2 changes: 1 addition & 1 deletion k8s/auth-service/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-auth-api
tag: prod-6ea06af8-1699219770
tag: prod-58e0f4e4-1699224315
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/device-monitor/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ images:
deviceMonitor: eu.gcr.io/airqo-250220/airqo-device-monitor-api
celeryBeat: eu.gcr.io/airqo-250220/airqo-device-monitor-celery-beat
celeryWorker: eu.gcr.io/airqo-250220/airqo-device-monitor-celery-worker
tag: prod-6ea06af8-1699219770
tag: prod-58e0f4e4-1699224315
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/device-registry/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-device-registry-api
tag: prod-6ea06af8-1699219770
tag: prod-58e0f4e4-1699224315
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/device-registry/values-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 2
image:
repository: eu.gcr.io/airqo-250220/airqo-stage-device-registry-api
tag: stage-c32fcdc5-1699219582
tag: stage-86bad23b-1699224239
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/exceedance/values-prod-airqo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ app:
configmap: env-exceedance-production
image:
repository: eu.gcr.io/airqo-250220/airqo-exceedance-job
tag: prod-6ea06af8-1699219770
tag: prod-58e0f4e4-1699224315
nameOverride: ''
fullnameOverride: ''
2 changes: 1 addition & 1 deletion k8s/exceedance/values-prod-kcca.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ app:
configmap: env-exceedance-production
image:
repository: eu.gcr.io/airqo-250220/kcca-exceedance-job
tag: prod-6ea06af8-1699219770
tag: prod-58e0f4e4-1699224315
nameOverride: ''
fullnameOverride: ''
2 changes: 1 addition & 1 deletion k8s/gp-model/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
namespace: production
configMap: env-gp-model-production
images:
tag: prod-6ea06af8-1699219770
tag: prod-58e0f4e4-1699224315
repositories:
cronJob: eu.gcr.io/airqo-250220/airqo-gp-model-job
brokerConsumer: eu.gcr.io/airqo-250220/airqo-gp-model-broker-consumer
Expand Down
2 changes: 1 addition & 1 deletion k8s/incentives/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-incentives-api
tag: prod-6ea06af8-1699219770
tag: prod-58e0f4e4-1699224315
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/predict/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ images:
predictJob: eu.gcr.io/airqo-250220/airqo-predict-job
trainJob: eu.gcr.io/airqo-250220/airqo-train-job
predictPlaces: eu.gcr.io/airqo-250220/airqo-predict-places-air-quality
tag: prod-6ea06af8-1699219770
tag: prod-58e0f4e4-1699224315
api:
name: airqo-prediction-api
label: prediction-api
Expand Down
58 changes: 58 additions & 0 deletions src/incentives/bin/cronJob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const cron = require("node-cron");
const SimModel = require("@models/Sim");
const constants = require("@config/constants");
const log4js = require("log4js");
const logger = log4js.getLogger(
`${constants.ENVIRONMENT} -- bin/cronJob script`
);
const checkStatus = require("@utils/create-sim").checkStatus;
const secondsDelayBetweenRequests = 20000;
const internetDataBalanceThreshold = 5;

// Everyday at midnight
cron.schedule("0 0 * * *", async () => {
try {
const batchSize = 100; // Process 100 SIM cards at a time
let skip = 0;

const simCards = await SimModel("airqo").find({}).select("_id").lean();

while (true) {
const simBatch = simCards.slice(skip, skip + batchSize);

if (simBatch.length === 0) {
break;
}

await processSimCardsWithDelay(simBatch);

skip += batchSize;
}
} catch (error) {
logger.error(
`An error occurred in the cron job --- ${JSON.stringify(error)}`
);
}
});

async function processSimCardsWithDelay(simBatch) {
for (const sim of simBatch) {
const responseFromCheckStatus = await checkStatus({
query: { tenant: "airqo" },
params: { sim_id: sim._id },
});

// Check if data.balance is less than the declared threshold and log it
if (
responseFromCheckStatus.success &&
responseFromCheckStatus.data.balance < internetDataBalanceThreshold
) {
logger.info(
`SIM card ${sim._id} has a balance less than ${internetDataBalanceThreshold}`
);
}
await new Promise((resolve) =>
setTimeout(resolve, secondsDelayBetweenRequests)
);
}
}
35 changes: 35 additions & 0 deletions src/incentives/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/incentives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"mongoose-unique-validator": "^2.0.3",
"morgan": "~1.9.0",
"mtn-momo": "^2.0.0",
"node-cron": "^3.0.2",
"node-fetch": "^2.6.1",
"node-schedule": "^2.1.1",
"nodemailer": "^6.9.4",
Expand Down

0 comments on commit 0b88eec

Please sign in to comment.