Added Scheduled task to get stats for template usage

Currently some pages are timing out due to the time it takes to perform
database queries. This is an attempt to improve the performance by
performing the query against the notification history table once a day
and use the notification table for a delta between midnight and the when
the page is run and combine the results.

- Added Celery task for doing the work
- Added a dao to handle the insert and update of the stats table
- Updated tests to test the new functionality
This commit is contained in:
Richard Chapman
2017-11-09 10:32:39 +00:00
parent ab43803453
commit ff911c30d6
8 changed files with 288 additions and 11 deletions

View File

@@ -11,6 +11,10 @@ from notifications_utils.s3 import s3upload
from app.aws import s3
from app import notify_celery
from app.dao.services_dao import (
dao_fetch_monthly_historical_stats_by_template
)
from app.dao.stats_template_usage_by_month_dao import insert_or_update_stats_for_template
from app.performance_platform import total_sent_notifications, processing_time
from app import performance_platform_client
from app.dao.date_util import get_month_start_and_end_date_in_utc
@@ -402,3 +406,17 @@ def check_job_status():
queue=QueueNames.JOBS
)
raise JobIncompleteError("Job(s) {} have not completed.".format(job_ids))
@notify_celery.task(name='daily-stats-template_usage_by_month')
@statsd(namespace="tasks")
def daily_stats_template_usage_my_month():
results = dao_fetch_monthly_historical_stats_by_template()
for result in results:
insert_or_update_stats_for_template(
result.template_id,
result.month.month,
result.year.year,
result.count
)