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

Create 'retries' gem #518

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@
[submodule "gems/json-jwt/1.16/_src"]
path = gems/json-jwt/1.16/_src
url = https://github.com/nov/json-jwt.git
[submodule "gems/retries/0.0.5/_src"]
path = gems/retries/0.0.5/_src
url = https://github.com/ooyala/retries.git
[submodule "gems/web-push/3.0/_src"]
path = gems/web-push/3.0/_src
url = https://github.com/pushpad/web-push.git
Expand Down
1 change: 1 addition & 0 deletions gems/retries/0.0.5/_src
Submodule _src added at 9622c6
10 changes: 10 additions & 0 deletions gems/retries/0.0.5/_test/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Write Ruby code to test the RBS.
# It is type checked by `steep check` command.

require "retries"

Retries.sleep_enabled = Retries.sleep_enabled

with_retries max_tries: 10, base_sleep_seconds: 1.2, max_sleep_seconds: 3.4, handler: ->(e,a,t){}, rescue: [StandardError] do |attempt|
puts "Attempt ##{attempt}"
end
15 changes: 15 additions & 0 deletions gems/retries/0.0.5/retries.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Retries
VERSION: String

attr_accessor self.sleep_enabled: bool
end

module Kernel
def with_retries: [T] (?max_tries: Integer?,
?base_sleep_seconds: Numeric?,
?max_sleep_seconds: Numeric?,
?handler: (^(Exception exception, Integer attempts, Float time) -> void)?,
?rescue: Exception | Array[Exception] | nil,
) { (Integer attempt_number) -> T } -> T
| [T] (Hash[Symbol, untyped] opts) { (Integer attempt_number) -> T } -> T
end