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

Add flags to prevent code running in envs where dfe-analytics isn't set up #130

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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 lib/dfe/analytics/entity_table_check_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Analytics
# To ensure BigQuery is in sync with the database
class EntityTableCheckJob < AnalyticsJob
def perform
return unless DfE::Analytics.entity_table_checks_enabled?
return unless DfE::Analytics.enabled? && DfE::Analytics.entity_table_checks_enabled?

entity_tag = Time.now.strftime('%Y%m%d%H%M%S')
DfE::Analytics.entities_for_analytics.each do |entity_name|
Expand Down
5 changes: 5 additions & 0 deletions lib/dfe/analytics/load_entity_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class LoadEntityBatch < AnalyticsJob
BQ_BATCH_MAX_BYTES = 10_000_000

def perform(model_class_arg, ids, entity_tag)
unless DfE::Analytics.enabled?
ericaporter marked this conversation as resolved.
Show resolved Hide resolved
Rails.logger.info('Bulk upload only available when DfE::Analytics is enabled, please check it is enabled in this env')
return
end

model_class = resolve_model_class(model_class_arg)

events = create_events(model_class, ids, entity_tag)
Expand Down
2 changes: 2 additions & 0 deletions lib/dfe/analytics/services/entity_table_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def entity_table_check_data(entity_name, order_column)
end

def send_entity_table_check_event(entity_name, entity_type, entity_tag, order_column)
return unless DfE::Analytics.enabled?

ericaporter marked this conversation as resolved.
Show resolved Hide resolved
entity_table_check_event = build_event_for(entity_name, entity_type, entity_tag, order_column)
DfE::Analytics::SendEvents.perform_later([entity_table_check_event])
end
Expand Down
17 changes: 17 additions & 0 deletions spec/dfe/analytics/entity_table_check_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,25 @@
end

describe '#perform' do
context 'when dfe-analytics is not enabled' do
before do
allow(DfE::Analytics).to receive(:enabled?).and_return(false)
allow(DfE::Analytics).to receive(:entity_table_checks_enabled?).and_return(true)
allow(DfE::Analytics).to receive(:entities_for_analytics).and_return(%w[Candidate Application])
end

it 'does not call EntityTableChecks' do
expect(DfE::Analytics::Services::EntityTableChecks).not_to receive(:call)

described_class.new.perform
end
end

context 'when entity table checks are not enabled' do
before do
allow(DfE::Analytics).to receive(:enabled?).and_return(true)
allow(DfE::Analytics).to receive(:entity_table_checks_enabled?).and_return(false)
allow(DfE::Analytics).to receive(:entities_for_analytics).and_return(%w[Candidate Application])
end
ericaporter marked this conversation as resolved.
Show resolved Hide resolved

it 'does not call EntityTableChecks' do
Expand All @@ -34,6 +50,7 @@

context 'when entity table checks are enabled' do
before do
allow(DfE::Analytics).to receive(:enabled?).and_return(true)
allow(DfE::Analytics).to receive(:entity_table_checks_enabled?).and_return(true)
allow(DfE::Analytics).to receive(:entities_for_analytics).and_return(%w[Candidate Application])
end
Expand Down
1 change: 1 addition & 0 deletions spec/dfe/analytics/load_entity_batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
end

before do
allow(DfE::Analytics).to receive(:enabled?).and_return(true)
allow(DfE::Analytics::SendEvents).to receive(:perform_now)

allow(DfE::Analytics).to receive(:allowlist).and_return({
Expand Down
Loading