Skip to content

Commit

Permalink
Allow queue to be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanjbrown committed Apr 21, 2022
1 parent 570902d commit d58f3d1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ en:
async:
description: Whether to use ActiveJob or dispatch events immediately.
default: true
queue:
description: Which ActiveJob queue to put events on
default: ":default"
bigquery_table_name:
description: The name of the BigQuery table we’re writing to.
default: ENV['BIGQUERY_TABLE_NAME']
Expand Down
2 changes: 2 additions & 0 deletions lib/dfe/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def self.config
configurables = %i[
log_only
async
queue
bigquery_table_name
bigquery_project_id
bigquery_dataset
Expand All @@ -67,6 +68,7 @@ def self.configure
config.environment ||= ENV.fetch('RAILS_ENV', 'development')
config.log_only ||= false
config.async ||= true
config.queue ||= :default
end

def self.enabled?
Expand Down
2 changes: 2 additions & 0 deletions lib/dfe/analytics/send_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module DfE
module Analytics
class SendEvents < ActiveJob::Base
queue_as { DfE::Analytics.config.queue }

def self.do(events)
if DfE::Analytics.async?
perform_later(events)
Expand Down
11 changes: 11 additions & 0 deletions lib/dfe/analytics/testing/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ def stub_analytics_event_submission
stub_request(:post, /bigquery.googleapis.com/)
.to_return(status: 200, body: '{}', headers: { 'Content-Type' => 'application/json' })
end

def with_analytics_config(options)
old_config = DfE::Analytics.config.dup
DfE::Analytics.configure do |config|
options.each { |option, value| config[option] = value }
end

yield
ensure
DfE::Analytics.instance_variable_set(:@config, old_config)
end
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/requests/analytics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,22 @@ def index
expect(payload['request_uuid']).to eq(request_uuid)
end).to have_been_made
end

context "when a queue is specified" do
it 'uses the specified queue' do
with_analytics_config(queue: :my_custom_queue) do
expect {
get '/example/path'
}.to have_enqueued_job.on_queue(:my_custom_queue)
end
end
end

context "when no queue is specified" do
it 'uses the default queue' do
expect {
get '/example/path'
}.to have_enqueued_job.on_queue(:default)
end
end
end

0 comments on commit d58f3d1

Please sign in to comment.