From 19c004126e32c4b110bcbc7cd6d69708aa4725b8 Mon Sep 17 00:00:00 2001 From: Tristan Hill <878258+tbhi@users.noreply.github.com> Date: Thu, 12 Dec 2024 09:45:43 +0000 Subject: [PATCH 1/3] only cache one meter collection per school --- app/services/schools/school_regeneration_service.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/services/schools/school_regeneration_service.rb b/app/services/schools/school_regeneration_service.rb index eb28e2bddd..dba7f83d01 100644 --- a/app/services/schools/school_regeneration_service.rb +++ b/app/services/schools/school_regeneration_service.rb @@ -8,14 +8,14 @@ def initialize(school:, logger: Rails.logger) def perform meter_collection = validate_and_persist_readings continue = run_aggregation(meter_collection) + remove_meter_collection_from_cache if continue cache_meter_collection(meter_collection) regenerate_school_metrics(meter_collection) - return true + true else @logger.error('Unable to continue with regeneration') - remove_meter_collection_from_cache - return false + false end end From c8728c1fe82ac7c7aba067918ad7e764be1c2546 Mon Sep 17 00:00:00 2001 From: Tristan Hill <878258+tbhi@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:31:54 +0000 Subject: [PATCH 2/3] more --- app/services/aggregate_school_service.rb | 2 +- app/services/schools/school_regeneration_service.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/services/aggregate_school_service.rb b/app/services/aggregate_school_service.rb index 00af4fa9d4..9992cff1fc 100644 --- a/app/services/aggregate_school_service.rb +++ b/app/services/aggregate_school_service.rb @@ -6,7 +6,7 @@ def initialize(active_record_school) end def aggregate_school - Rails.cache.fetch(cache_key) do + Rails.cache.fetch(cache_key, expires_in: 2.days) do meter_collection = Amr::AnalyticsMeterCollectionFactory.new(@active_record_school).validated AggregateDataService.new(meter_collection).aggregate_heat_and_electricity_meters diff --git a/app/services/schools/school_regeneration_service.rb b/app/services/schools/school_regeneration_service.rb index dba7f83d01..eb28e2bddd 100644 --- a/app/services/schools/school_regeneration_service.rb +++ b/app/services/schools/school_regeneration_service.rb @@ -8,14 +8,14 @@ def initialize(school:, logger: Rails.logger) def perform meter_collection = validate_and_persist_readings continue = run_aggregation(meter_collection) - remove_meter_collection_from_cache if continue cache_meter_collection(meter_collection) regenerate_school_metrics(meter_collection) - true + return true else @logger.error('Unable to continue with regeneration') - false + remove_meter_collection_from_cache + return false end end From e46d7610df60c14237a18dc41426d9289b3d964b Mon Sep 17 00:00:00 2001 From: Tristan Hill <878258+tbhi@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:32:06 +0000 Subject: [PATCH 3/3] more --- .ebextensions/cronjob.config | 3 ++- app/services/aggregate_school_service.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.ebextensions/cronjob.config b/.ebextensions/cronjob.config index 8965d7d5e8..89fcfdecaf 100644 --- a/.ebextensions/cronjob.config +++ b/.ebextensions/cronjob.config @@ -106,9 +106,10 @@ files: # 0 08 * * 1 root run-webapp-job i18n:transifex_load # - # Delete old alert content + # Clean ups # 0 1 * * 7 root run-webapp-job alerts:delete_alert_content + 15 5 * * * root run-as-webapp bin/rails r Rails.cache.cleanup # # Send Good Job queue metrics to AWS Cloudwatch # diff --git a/app/services/aggregate_school_service.rb b/app/services/aggregate_school_service.rb index 9992cff1fc..0d2922e13c 100644 --- a/app/services/aggregate_school_service.rb +++ b/app/services/aggregate_school_service.rb @@ -6,7 +6,7 @@ def initialize(active_record_school) end def aggregate_school - Rails.cache.fetch(cache_key, expires_in: 2.days) do + Rails.cache.fetch(cache_key, expires_in: 3.days) do meter_collection = Amr::AnalyticsMeterCollectionFactory.new(@active_record_school).validated AggregateDataService.new(meter_collection).aggregate_heat_and_electricity_meters