Skip to content

Commit e1a4b55

Browse files
committed
request summary command
1 parent 808bf04 commit e1a4b55

6 files changed

Lines changed: 108 additions & 0 deletions

File tree

infrastructure/modules/container-apps/jobs.tf

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
locals {
2+
scheduled_jobs = {
3+
collect_metrics = {
4+
cron_expression = "0 */6 * * *"
5+
environment_variables = {
6+
ENVIRONMENT = var.environment
7+
}
8+
job_short_name = "rs"
9+
job_container_args = "request_summary"
10+
}
11+
}
12+
}
13+
114
module "db_setup" {
215
source = "../dtos-devops-templates/infrastructure/modules/container-app-job"
316

@@ -25,3 +38,54 @@ module "db_setup" {
2538
]
2639

2740
}
41+
42+
module "scheduled_jobs" {
43+
source = "../dtos-devops-templates/infrastructure/modules/container-app-job"
44+
45+
for_each = local.scheduled_jobs
46+
47+
name = "${var.app_short_name}-${each.value.job_short_name}-${var.environment}"
48+
container_app_environment_id = var.container_app_environment_id
49+
resource_group_name = azurerm_resource_group.main.name
50+
51+
fetch_secrets_from_app_key_vault = var.fetch_secrets_from_app_key_vault
52+
app_key_vault_id = var.app_key_vault_id
53+
54+
container_command = ["/bin/sh", "-c"]
55+
container_args = [
56+
"python manage.py ${each.value.job_container_args}"
57+
]
58+
59+
docker_image = var.docker_image
60+
replica_retry_limit = 0
61+
user_assigned_identity_ids = flatten([
62+
[module.azure_blob_storage_identity.id],
63+
var.deploy_database_as_container ? [] : [module.db_connect_identity[0].id]
64+
])
65+
66+
environment_variables = merge(
67+
local.common_env,
68+
{
69+
"STORAGE_ACCOUNT_NAME" = module.storage.storage_account_name,
70+
"BLOB_MI_CLIENT_ID" = module.azure_blob_storage_identity.client_id,
71+
},
72+
each.value.environment_variables,
73+
var.deploy_database_as_container ? local.container_db_env : local.azure_db_env
74+
)
75+
secret_variables = merge(
76+
# { APPLICATIONINSIGHTS_CONNECTION_STRING = var.app_insights_connection_string },
77+
var.deploy_database_as_container ? { DATABASE_PASSWORD = resource.random_password.admin_password[0].result } : {}
78+
)
79+
80+
# alerts
81+
action_group_id = var.action_group_id
82+
enable_alerting = var.enable_alerting
83+
log_analytics_workspace_id = var.log_analytics_workspace_audit_id
84+
85+
# Ensure RBAC role assignments are created before the job definition finalizes
86+
depends_on = [
87+
module.blob_storage_role_assignment,
88+
]
89+
90+
cron_expression = each.value.cron_expression
91+
}

lung_cancer_screening/questions/management/__init__.py

Whitespace-only changes.

lung_cancer_screening/questions/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import logging
2+
3+
from django.core.management.base import BaseCommand, CommandError
4+
from lung_cancer_screening.questions.services.request_summary import RequestSummary
5+
6+
logger = logging.getLogger(__name__)
7+
8+
class Command(BaseCommand):
9+
help = "Counts the number of submitted requests."
10+
11+
def handle(self, *args, **options):
12+
logger.info("Command: SubmittedCount.")
13+
try:
14+
rs = RequestSummary()
15+
summary = rs.get_summary()
16+
17+
self.stdout.write(str(summary))
18+
19+
except Exception as e:
20+
logger.error(e, exc_info=True)
21+
raise CommandError(e)

lung_cancer_screening/questions/services/__init__.py

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import logging
2+
from ..models.response_set import ResponseSet
3+
4+
logger = logging.getLogger(__name__)
5+
6+
class RequestSummary:
7+
8+
def __init__(self):
9+
logger.info("RequestSummary: init")
10+
11+
def get_submitted_count(self):
12+
13+
return ResponseSet.objects.submitted().count()
14+
15+
def get_count(self):
16+
17+
return ResponseSet.objects.count()
18+
19+
def get_summary(self):
20+
return {
21+
"total": self.get_count(),
22+
"submitted": self.get_submitted_count(),
23+
}

0 commit comments

Comments
 (0)