module Fluere::Workflow

Constants

EXECUTION_METHOD

Public Class Methods

aws_name() click to toggle source

Stupid AWS doesn't allow colons in workflow or activity type names…

# File lib/fluere/workflow.rb, line 60
def self.aws_name
  name.gsub(/:/, '_')
end

Public Instance Methods

activities_class() click to toggle source
# File lib/fluere/workflow.rb, line 55
def activities_class
  @activities_class ||= const_set('Activities', Class.new {
    extend AWS::Flow::Activities

    # Stupid AWS doesn't allow colons in workflow or activity type names...
    def self.aws_name
      name.gsub(/:/, '_')
    end
  }).tap { |a| Fluere.activities << a }
end
activity(name, &block) click to toggle source
# File lib/fluere/workflow.rb, line 32
def activity(name, &block)
  # Define a method to be used as the activity implementation
  activities_class.send :define_method, name, &block

  # Wire this method in as an AWS Flow activity
  activities_class.activity(name) {
    Fluere.default_activity_options.merge(
      prefix_name: activities_class.aws_name,
      version:     Fluere::Config.version,
    )
  }

  # Establish a shortcut method for the decider implementation to use to
  # call this activity as though it were a local method
  decider_class.send :define_method, name do |*args|
    if Fluere.stubbed?
      activities_class.new.send(name, *args)
    else
      activities_client.send(name, *args)
    end
  end
end
decider(&block) click to toggle source
# File lib/fluere/workflow.rb, line 5
def decider(&block)
  # Set the provided block as the workflow execution method
  decider_class.send :define_method, EXECUTION_METHOD, &block

  # Wire that method in as an AWS Flow workflow
  decider_class.workflow(EXECUTION_METHOD) {
    Fluere.default_workflow_options.merge(
      prefix_name:       decider_class.aws_name,
      version:           Fluere::Config.version,
    )
  }

  # Give the decider a direct reference to activities for use in stubbed
  # implementations
  activities_class.tap do |klass|
    decider_class.send(:define_method, :activities_class) { klass }
  end

  # Establish the activity client which will be used in defining the helper
  # method for each activity (when we are not stubbed)
  decider_class.activity_client(:activities_client) {{
    prefix_name: activities_class.aws_name,
    version:     Fluere::Config.version,
    task_list:   Fluere.activities_task_list
  }}
end
decider_class() click to toggle source
# File lib/fluere/workflow.rb, line 66
def decider_class
  @decider_class ||= const_set('Decider', Class.new {
    extend AWS::Flow::Workflows

    # Stupid AWS doesn't allow colons in workflow or activity type names...
    def self.aws_name
      name.gsub(/:/, '_')
    end

    def send_async(*args)
      if Fluere.stubbed?
        activities_class.new.send(*args)
      else
        activities_client.send_async(*args)
      end
    end

    def wait_for_all(*args)
      unless Fluere.stubbed?
        super
      end
    end
  }).tap { |d| Fluere.workflows << d }
end
send_async(*args) click to toggle source
# File lib/fluere/workflow.rb, line 75
def send_async(*args)
  if Fluere.stubbed?
    activities_class.new.send(*args)
  else
    activities_client.send_async(*args)
  end
end
wait_for_all(*args) click to toggle source
Calls superclass method
# File lib/fluere/workflow.rb, line 83
def wait_for_all(*args)
  unless Fluere.stubbed?
    super
  end
end
workflow_client() click to toggle source
# File lib/fluere/workflow.rb, line 91
def workflow_client
  @workflow_client ||= AWS::Flow.workflow_client(
    Fluere.swf.client,
    Fluere.domain
  ) {{
    workflow_name:    decider_class.aws_name,
    execution_method: EXECUTION_METHOD,
    version:          Fluere::Config.version,
    task_list:        Fluere.decisions_task_list
  }}
end