Class: AWS::Flow::GenericClient

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/decider/generic_client.rb

Overview

A generic activity client.

Direct Known Subclasses

GenericActivityClient, WorkflowClient

Instance Attribute Summary collapse

Instance Method Summary collapse

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_mapObject

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

#decision_contextObject

Returns The decision context for this client.

Returns:

  • The decision context for this client.



172
173
174
# File 'lib/aws/decider/generic_client.rb', line 172

def decision_context
  FlowFiber.current[:decision_context]
end

#exponential_retry(method_name, *args, &block) ⇒ Object

Retries the given method using an exponential fallback function.



98
99
100
101
# File 'lib/aws/decider/generic_client.rb', line 98

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)
  options = Utilities::interpret_block_for_options(self.class.default_option_class, block)
  method_names.each { |method_name| @option_map[method_name.to_sym] = options }
end

#retry(method_name, retry_function, *args, &block) ⇒ Object

Retries the given method using an optional retry function and block of RetryOptions.

Parameters:

  • method_name

    The activity to retry.

  • retry_function

    The retry function to use

  • args

    Arguments to send to the method named in the ‘method_name` parameter.

  • block

    The RetryOptions to set.



161
162
163
164
165
166
167
168
# File 'lib/aws/decider/generic_client.rb', line 161

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

Note:

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.

Examples:

The following two calls are equivalent.

foo.send_async :bar # plus args and block if appropriate

task do
  foo.send :bar # plus args and block if appropriate
end

Parameters:

  • task

    The task to execute.

  • args

    A number of arguments used to start the task execution.

  • block

    A code block with additional options to start the task execution.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# 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?
    modified_options = 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
    modified_options = Proc.new do
      result = block.call
      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 modified_options = Proc.new do |x|
      result = block.call(x)
      result.return_on_start = true
      result
    end
  end
  self.send(task, *args, &modified_options)
end

#with_opts(opts = {}) ⇒ Object

Sets a map of options for this client.

Parameters:

  • opts (defaults to: {})

    The options to set.



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
  options = klass.new(opts)
  modified_instance = self.dup
  options = klass.new(Utilities::merge_all_options(modified_instance.options, options))
  modified_instance.options = options
  modified_instance
end