-
Notifications
You must be signed in to change notification settings - Fork 48
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 a simple context plugin #43
Changes from 2 commits
94b1def
4e35ddc
43da6cd
ea5b10f
aeb16a7
de3fcb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
## HEAD | ||
|
||
* Added contexts feature. Thanks to @apurvis. | ||
|
||
## 3.0.2 | ||
|
||
* Add configuration and options validation. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,22 @@ | |
module Retriable | ||
module_function | ||
|
||
def self.configure | ||
def configure | ||
yield(config) | ||
end | ||
|
||
def config | ||
@config ||= Config.new | ||
end | ||
|
||
def retriable_with_context(context_key, options = {}, &block) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could even just name the method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I named it I agree There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
i tend to view adding methods to point being, i think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I had to write it again I might leave out the kernel extension, but I don't want to break it for people upgrading. I changed it to name it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah you'd have to deprecate it and then wait until the next major version... even then it might not be worth breaking people's shit. if you were considering that approach though, you could deprecate it now. |
||
if !config.context.key?(context_key) | ||
raise ArgumentError, "#{context_key} not found in Retriable.config.context" | ||
end | ||
|
||
retriable(config.context[context_key].merge(options), &block) if block | ||
end | ||
|
||
def retriable(opts = {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you're going to declare the &block in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think i need the block here because we call yield here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah you don't need it, but it does make it clear that the method takes a block - just makes the method signature fully explicit because otherwise the |
||
local_config = opts.empty? ? config : Config.new(config.to_h.merge(opts)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ class Config | |
:timeout, | ||
:on, | ||
:on_retry, | ||
:context, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plural There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'll change that. |
||
].freeze | ||
|
||
attr_accessor(*ATTRIBUTES) | ||
|
@@ -27,6 +28,7 @@ def initialize(opts = {}) | |
@timeout = nil | ||
@on = [StandardError] | ||
@on_retry = nil | ||
@context = {} | ||
|
||
opts.each do |k, v| | ||
raise ArgumentError, "#{k} is not a valid option" if !ATTRIBUTES.include?(k) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're missing a version number here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh what I usually do is put new feature/bug fixes in HEAD, and then when I cut a new version, I'll move the new stuff into that version. Since sometimes I collect a few features or bug fixes before doing a version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whatever you prefer; i'm just used to always having the next version being the first line of the changelog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't always know if the next version will be major, minor, or patch until I know everything going into it. So I keep it HEAD until I cut the version.