Class: AWS::Flow::GenericClient
- Inherits:
-
Object
- Object
- AWS::Flow::GenericClient
- Defined in:
- lib/aws/decider/generic_client.rb
Overview
A generic activity client.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#option_map ⇒ Object
The option map for the client.
Instance Method Summary collapse
-
#_retry(method_name, retry_function, block, args = NoInput.new) ⇒ Object
private
Retries the given method using an optional retry function and block of RetryOptions.
-
#_retry_with_options(lambda_to_execute, retry_function, retry_options, args = NoInput.new) ⇒ Object
private
Used by #retry.
- #bail_if_external ⇒ Object private
-
#decision_context ⇒ Object
The decision context for this client.
-
#exponential_retry(method_name, *args, &block) ⇒ Object
Retries the given method using an exponential fallback function.
-
#initialize(*args) ⇒ GenericClient
constructor
Creates a new generic client.
- #reconfigure(*method_names, &block) ⇒ Object
-
#retry(method_name, retry_function, *args, &block) ⇒ Object
Retries the given method using an optional retry function and block of RetryOptions.
-
#send_async(task, *args, &block) ⇒ Object
Starts an asynchronous execution of a task.
-
#with_opts(opts = {}) ⇒ Object
Sets a map of options for this client.
Constructor Details
#initialize(*args) ⇒ GenericClient
Creates a new generic client.
26 27 28 |
# File 'lib/aws/decider/generic_client.rb', line 26 def initialize(*args) @option_map = {} end |
Instance Attribute Details
#option_map ⇒ Object
The option map for the client.
23 24 25 |
# File 'lib/aws/decider/generic_client.rb', line 23 def option_map @option_map end |
Instance Method Details
#_retry(method_name, retry_function, block, args = NoInput.new) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Retries the given method using an optional retry function and block of RetryOptions.
147 148 149 150 151 |
# File 'lib/aws/decider/generic_client.rb', line 147 def _retry(method_name, retry_function, block, args = NoInput.new) bail_if_external = Utilities::(ExponentialRetryOptions, block) (lambda { self.send(method_name, *args) }, retry_function, ) end |
#_retry_with_options(lambda_to_execute, retry_function, retry_options, args = NoInput.new) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Used by #retry
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/aws/decider/generic_client.rb', line 114 def (lambda_to_execute, retry_function, , args = NoInput.new) retry_policy = RetryPolicy.new(retry_function, ) output = Utilities::AddressableFuture.new result = nil failure = nil error_handler do |t| t.begin do = AsyncRetryingExecutor.new(retry_policy, self.decision_context.workflow_clock, self.decision_context.workflow_context.decision_task.workflow_execution.run_id, .return_on_start) result = .execute(lambda_to_execute) end t.rescue(Exception) do |error| failure = error end t.ensure do if failure.nil? output.set(result) else output.set(nil) end end end return output if .return_on_start output.get raise failure unless failure.nil? return output.get end |
#bail_if_external ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 |
# File 'lib/aws/decider/generic_client.rb', line 51 def bail_if_external raise "You cannot use this function outside of a workflow definition" if Utilities::is_external end |
#decision_context ⇒ Object
Returns The decision context for this client.
179 180 181 |
# File 'lib/aws/decider/generic_client.rb', line 179 def decision_context FlowFiber.current[:decision_context] end |
#exponential_retry(method_name, *args, &block) ⇒ Object
Retries the given method using an exponential fallback function.
105 106 107 108 |
# File 'lib/aws/decider/generic_client.rb', line 105 def exponential_retry(method_name, *args, &block) future = self._retry(method_name, FlowConstants.exponential_retry_function, block, args) Utilities::drill_on_future(future) end |
#reconfigure(*method_names, &block) ⇒ Object
45 46 47 48 |
# File 'lib/aws/decider/generic_client.rb', line 45 def reconfigure(*method_names, &block) = Utilities::(self.class.default_option_class, block) method_names.each { |method_name| @option_map[method_name.to_sym] = } end |
#retry(method_name, retry_function, *args, &block) ⇒ Object
Retries the given method using an optional retry function and block of RetryOptions.
168 169 170 171 172 173 174 175 |
# File 'lib/aws/decider/generic_client.rb', line 168 def retry(method_name, retry_function, *args, &block) if retry_function.is_a? Fixnum retry_time = retry_function retry_function = lambda {|first_attempt, time_of_failure, attempt| retry_time} end future = self._retry(method_name, retry_function, block, args) Utilities::drill_on_future(future) end |
#send_async(task, *args, &block) ⇒ Object
Trying to use #send_async outside of a workflow will fail with an exception.
Starts an asynchronous execution of a task. This method returns immediately; it does not wait for the task to complete.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/aws/decider/generic_client.rb', line 74 def send_async(task, *args, &block) bail_if_external # If there is no block, just make a block for immediate return. if block.nil? = Proc.new{ {:return_on_start => true } } # If there is a block, and it doesn't take any arguments, it will evaluate to a hash. Add an option to the hash. elsif block.arity == 0 = Proc.new do result = block.call # We need to copy the hash to make sure that we don't mutate it result = result.dup result[:return_on_start] = true result end # Otherwise, it will expect an options object passed in, and will do # things on that object. So make our new Proc do that, and add an # option. else = Proc.new do |x| result = block.call(x) # Same as the above dup, we'll copy to avoid any possible mutation # of inputted objects result = result.dup result.return_on_start = true result end end self.send(task, *args, &) end |
#with_opts(opts = {}) ⇒ Object
Sets a map of options for this client.
36 37 38 39 40 41 42 43 |
# File 'lib/aws/decider/generic_client.rb', line 36 def with_opts(opts = {}) klass = self.class.default_option_class = klass.new(opts) modified_instance = self.dup = klass.new(Utilities::(modified_instance., )) modified_instance. = modified_instance end |