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 config options: queue name, BQ timeout, BQ retries #1

Merged
merged 2 commits into from
Apr 21, 2022

Conversation

duncanjbrown
Copy link
Contributor

Clients can now configure the ActiveJob queue name, plus the BigQuery timeout and retry count options.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DfE::Analytics.config and old_config are the same thing (Ruby is pass by reference 😛 , see pry session below), so you should probably dup config:

Suggested change
old_config = DfE::Analytics.config
old_config = DfE::Analytics.config.dup

Pry session:

From: /Users/misaka/Code/DfE/dfe-analytics/lib/dfe/analytics/testing/helpers.rb:48 DfE::Analytics::Testing::Helpers#with_analytics_config:

    40: def with_analytics_config(options)
    41:   old_config = DfE::Analytics.config
    42:   DfE::Analytics.configure do |config|
    43:     options.each { |option, value| config[option] = value }
    44:   end
    45:
    46:   yield
    47: ensure
 => 48:   binding.pry
    49:   DfE::Analytics.instance_variable_set(:@config, old_config)
    50: end

[1] pry(#<RSpec::ExampleGroups::AnalyticsFlow::WhenAQueueIsSpecified>)> options
=> {:queue=>:my_custom_queue}
[2] pry(#<RSpec::ExampleGroups::AnalyticsFlow::WhenAQueueIsSpecified>)> DfE::Analytics.config[:queue]
=> :my_custom_queue
[3] pry(#<RSpec::ExampleGroups::AnalyticsFlow::WhenAQueueIsSpecified>)> old_config[:queue]
=> :my_custom_queue

Proof dup works:

[41] pry(#<RSpec::ExampleGroups::AnalyticsFlow::WhenAQueueIsSpecified>)> old_config = DfE::Analytics.config.dup
=> #<struct
 ...
 queue=:default,
 ...>
[42] pry(#<RSpec::ExampleGroups::AnalyticsFlow::WhenAQueueIsSpecified>)> DfE::Analytics.config[:queue] = :my_custom_queue
=> :my_custom_queue
[43] pry(#<RSpec::ExampleGroups::AnalyticsFlow::WhenAQueueIsSpecified>)> old_config[:queue]
=> :default
[44] pry(#<RSpec::ExampleGroups::AnalyticsFlow::WhenAQueueIsSpecified>)> DfE::Analytics.config[:queue]
=> :my_custom_queue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point, thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lesson: test your tests

Copy link
Contributor

@misaka misaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\o/

@duncanjbrown duncanjbrown merged commit 987ab7b into main Apr 21, 2022
@thomasleese thomasleese deleted the more-config-options branch July 9, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants