Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move to production #2436

Merged
merged 16 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
15936d6
scheduling daily SIM status checks
Baalmart Nov 4, 2023
1cb8c72
Merge branch 'staging' into hotfix-schedule-sim-status
Baalmart Nov 4, 2023
844e47e
Update device registry staging image tag to stage-86bad23b-1699224239
github-actions[bot] Nov 5, 2023
d77b717
Update AirQo exceedance production image tag to prod-58e0f4e4-1699224315
github-actions[bot] Nov 5, 2023
c042235
Update KCCA exceedance production image tag to prod-58e0f4e4-1699224315
github-actions[bot] Nov 5, 2023
0c7d270
Update incentives production image tag to prod-58e0f4e4-1699224315
github-actions[bot] Nov 5, 2023
df38a60
Update auth service production image tag to prod-58e0f4e4-1699224315
github-actions[bot] Nov 5, 2023
0881662
Update device registry production image tag to prod-58e0f4e4-1699224315
github-actions[bot] Nov 5, 2023
ab2703f
Update device monitor production images' tag to prod-58e0f4e4-1699224315
github-actions[bot] Nov 5, 2023
bf15ee9
Update airflow prod image tag to prod-58e0f4e4-1699224315
github-actions[bot] Nov 5, 2023
fd75612
Merge branch 'staging' into hotfix-schedule-sim-status
Baalmart Nov 5, 2023
5ee92d2
Update predict production image tag to prod-58e0f4e4-1699224315
github-actions[bot] Nov 5, 2023
71bbd63
Update analytics production image tag to prod-58e0f4e4-1699224315
github-actions[bot] Nov 5, 2023
da59183
Update gp-model production image tag to prod-58e0f4e4-1699224315
github-actions[bot] Nov 5, 2023
db58dec
cronjob for checking the status of the sim card
Baalmart Nov 5, 2023
0517d92
Merge pull request #2425 from airqo-platform/hotfix-schedule-sim-status
Baalmart Nov 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading