senro_usecaser 0.2.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +23 -0
- data/README.md +850 -0
- data/examples/namespace_demo.rb +50 -15
- data/examples/order_system.rb +222 -34
- data/examples/sig/namespace_demo.rbs +35 -10
- data/examples/sig/order_system.rbs +196 -20
- data/lib/senro_usecaser/base.rb +387 -86
- data/lib/senro_usecaser/depends_on.rb +257 -0
- data/lib/senro_usecaser/hook.rb +28 -82
- data/lib/senro_usecaser/provider.rb +1 -1
- data/lib/senro_usecaser/retry_configuration.rb +131 -0
- data/lib/senro_usecaser/retry_context.rb +133 -0
- data/lib/senro_usecaser/version.rb +1 -1
- data/lib/senro_usecaser.rb +3 -0
- data/sig/generated/senro_usecaser/base.rbs +179 -37
- data/sig/generated/senro_usecaser/depends_on.rbs +197 -0
- data/sig/generated/senro_usecaser/hook.rbs +23 -35
- data/sig/generated/senro_usecaser/provider.rbs +1 -1
- data/sig/generated/senro_usecaser/retry_configuration.rbs +90 -0
- data/sig/generated/senro_usecaser/retry_context.rbs +101 -0
- data/sig/overrides.rbs +1 -2
- metadata +7 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Generated from lib/senro_usecaser/retry_context.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module SenroUsecaser
|
|
4
|
+
# Represents the context of a retry operation
|
|
5
|
+
#
|
|
6
|
+
# This class tracks the state of retry attempts including:
|
|
7
|
+
# - Current attempt number
|
|
8
|
+
# - Maximum attempts allowed
|
|
9
|
+
# - Elapsed time since first attempt
|
|
10
|
+
# - Whether a retry should occur
|
|
11
|
+
#
|
|
12
|
+
# @example Basic usage in on_failure hook
|
|
13
|
+
# on_failure do |input, result, context|
|
|
14
|
+
# if context.attempt < 3
|
|
15
|
+
# context.retry!(wait: 1.0)
|
|
16
|
+
# end
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# @example With modified input
|
|
20
|
+
# on_failure do |input, result, context|
|
|
21
|
+
# if result.errors.first&.code == :rate_limited
|
|
22
|
+
# context.retry!(input: input.with_reduced_batch_size, wait: 5.0)
|
|
23
|
+
# end
|
|
24
|
+
# end
|
|
25
|
+
class RetryContext
|
|
26
|
+
# Returns the current attempt number (1-indexed)
|
|
27
|
+
# : () -> Integer
|
|
28
|
+
attr_reader attempt: untyped
|
|
29
|
+
|
|
30
|
+
# Returns the maximum number of attempts allowed
|
|
31
|
+
# : () -> Integer?
|
|
32
|
+
attr_reader max_attempts: untyped
|
|
33
|
+
|
|
34
|
+
# Returns the time when the first attempt started
|
|
35
|
+
# : () -> Time
|
|
36
|
+
attr_reader started_at: untyped
|
|
37
|
+
|
|
38
|
+
# Returns the error from the last failed attempt
|
|
39
|
+
# : () -> Error?
|
|
40
|
+
attr_reader last_error: untyped
|
|
41
|
+
|
|
42
|
+
# Returns the input to use for the retry (nil means use original)
|
|
43
|
+
# : () -> untyped
|
|
44
|
+
attr_reader retry_input: untyped
|
|
45
|
+
|
|
46
|
+
# Returns the wait time before retrying
|
|
47
|
+
# : () -> (Float | Integer)?
|
|
48
|
+
attr_reader retry_wait: untyped
|
|
49
|
+
|
|
50
|
+
# Initializes a new retry context
|
|
51
|
+
#
|
|
52
|
+
# : (?max_attempts: Integer?) -> void
|
|
53
|
+
def initialize: (?max_attempts: Integer?) -> void
|
|
54
|
+
|
|
55
|
+
# Returns true if this is a retry (attempt > 1)
|
|
56
|
+
#
|
|
57
|
+
# : () -> bool
|
|
58
|
+
def retried?: () -> bool
|
|
59
|
+
|
|
60
|
+
# Returns the elapsed time since the first attempt
|
|
61
|
+
#
|
|
62
|
+
# : () -> Float
|
|
63
|
+
def elapsed_time: () -> Float
|
|
64
|
+
|
|
65
|
+
# Returns true if max_attempts has been reached
|
|
66
|
+
#
|
|
67
|
+
# : () -> bool
|
|
68
|
+
def exhausted?: () -> bool
|
|
69
|
+
|
|
70
|
+
# Returns true if a retry has been requested
|
|
71
|
+
#
|
|
72
|
+
# : () -> bool
|
|
73
|
+
def should_retry?: () -> bool
|
|
74
|
+
|
|
75
|
+
# Requests a retry with optional modified input and wait time
|
|
76
|
+
#
|
|
77
|
+
# @example Retry with default settings
|
|
78
|
+
# context.retry!
|
|
79
|
+
#
|
|
80
|
+
# @example Retry with wait time
|
|
81
|
+
# context.retry!(wait: 2.0)
|
|
82
|
+
#
|
|
83
|
+
# @example Retry with modified input
|
|
84
|
+
# context.retry!(input: modified_input, wait: 1.0)
|
|
85
|
+
#
|
|
86
|
+
# : (?input: untyped, ?wait: (Float | Integer)?) -> void
|
|
87
|
+
def retry!: (?input: untyped, ?wait: (Float | Integer)?) -> void
|
|
88
|
+
|
|
89
|
+
# Increments the attempt counter and resets retry state
|
|
90
|
+
# Called internally between retry attempts
|
|
91
|
+
#
|
|
92
|
+
# : (?last_error: Error?) -> void
|
|
93
|
+
def increment!: (?last_error: Error?) -> void
|
|
94
|
+
|
|
95
|
+
# Resets the retry request state
|
|
96
|
+
# Called internally after processing retry decision
|
|
97
|
+
#
|
|
98
|
+
# : () -> void
|
|
99
|
+
def reset_retry_state!: () -> void
|
|
100
|
+
end
|
|
101
|
+
end
|
data/sig/overrides.rbs
CHANGED
|
@@ -10,7 +10,6 @@ module SenroUsecaser
|
|
|
10
10
|
class Base
|
|
11
11
|
# Class methods that rbs-inline doesn't generate correctly
|
|
12
12
|
def self.organized_steps: () -> Array[Step]?
|
|
13
|
-
def self.
|
|
14
|
-
def self.input_class: () -> Class?
|
|
13
|
+
def self.output_schema: () -> (Class | Hash[Symbol, Class])?
|
|
15
14
|
end
|
|
16
15
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: senro_usecaser
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shogo Kawahara
|
|
@@ -37,19 +37,25 @@ files:
|
|
|
37
37
|
- lib/senro_usecaser/base.rb
|
|
38
38
|
- lib/senro_usecaser/configuration.rb
|
|
39
39
|
- lib/senro_usecaser/container.rb
|
|
40
|
+
- lib/senro_usecaser/depends_on.rb
|
|
40
41
|
- lib/senro_usecaser/error.rb
|
|
41
42
|
- lib/senro_usecaser/hook.rb
|
|
42
43
|
- lib/senro_usecaser/provider.rb
|
|
43
44
|
- lib/senro_usecaser/result.rb
|
|
45
|
+
- lib/senro_usecaser/retry_configuration.rb
|
|
46
|
+
- lib/senro_usecaser/retry_context.rb
|
|
44
47
|
- lib/senro_usecaser/version.rb
|
|
45
48
|
- sig/generated/senro_usecaser.rbs
|
|
46
49
|
- sig/generated/senro_usecaser/base.rbs
|
|
47
50
|
- sig/generated/senro_usecaser/configuration.rbs
|
|
48
51
|
- sig/generated/senro_usecaser/container.rbs
|
|
52
|
+
- sig/generated/senro_usecaser/depends_on.rbs
|
|
49
53
|
- sig/generated/senro_usecaser/error.rbs
|
|
50
54
|
- sig/generated/senro_usecaser/hook.rbs
|
|
51
55
|
- sig/generated/senro_usecaser/provider.rbs
|
|
52
56
|
- sig/generated/senro_usecaser/result.rbs
|
|
57
|
+
- sig/generated/senro_usecaser/retry_configuration.rbs
|
|
58
|
+
- sig/generated/senro_usecaser/retry_context.rbs
|
|
53
59
|
- sig/generated/senro_usecaser/version.rbs
|
|
54
60
|
- sig/overrides.rbs
|
|
55
61
|
homepage: https://github.com/kawahara/senro_usecaser
|