aws / aws-sdk-ruby

The official AWS SDK for Ruby.
https://aws.amazon.com/sdk-for-ruby/
Apache License 2.0
3.56k stars 1.22k forks source link

SWF: Ruby implementation does not accept a namespaced Workflow class when registering the Workflow #581

Closed rantonmattei closed 10 years ago

rantonmattei commented 10 years ago

If my workflow class is part of a namespace like shown below, I get the following error: ruby-2.1.2/gems/aws-sdk-1.42.0/lib/aws/core/client.rb:375:in `return_or_raise': Invalid name: MyWorkflows::HelloWorldWorkflow.hello (AWS::SimpleWorkflow::Errors::ValidationException)

A quick look to the doc @ http://docs.aws.amazon.com/amazonswf/latest/apireference/API_RegisterWorkflowType.html confirms that the RegisterWorkflowType API action cannot take a name with a colon.

The specified string must not start or end with whitespace. It must not contain a : (colon), / (slash), | (vertical bar), or any control characters (\u0000-\u001f | \u007f - \u009f). Also, it must not contain the literal string "arn".


So that raises at least 2 main concerns:


require_relative "../../swf_init"
require_relative "activities/hello"

# HelloWorldWorkflow class defines the workflows for the HelloWorld sample
module MyWorkflows
  class HelloWorldWorkflow
    extend AWS::Flow::Workflows

    workflow :hello do {
      version: HelloWorldInit::WF_VERSION,
      task_list: HelloWorldInit::WF_TASKLIST,
      execution_start_to_close_timeout: 3600,
    }
    end

    # Create an activity client using the activity_client method to schedule
    # activities
    activity_client(:hello_client) { { :from_class => "HelloActivity" } }

    # This is the entry point for the workflow
    def hello(name)
      # Use the activity client 'client' to invoke the say_hello activity
      hello_client.say_hello(name)
    end
  end
end
# Start a WorkflowWorker to work on the HelloWorldWorkflow tasks
HelloWorldInit.new.workflow_worker(MyWorkflows::HelloWorldWorkflow).start if $0 == __FILE__

# HelloWorldInit.new.workflow_worker eventually calls
# AWS::Flow::WorkflowWorker.new(domain.client, domain, WF_TASKLIST, workflow_class)
# workflow_class being MyWorkflows::HelloWorldWorkflow

trevorrowe commented 10 years ago

It looks like you logged this against the wrong repo. You are probably looking for https://github.com/aws/aws-flow-ruby.

rantonmattei commented 10 years ago

I doubt it is a Flow issue. Flow eventually calls the API with [ClassName].[MethodName] as name param (SimpleWorkflow service with RegisterWorkflowType action).

It is inherent to the SWF service, I guess. The main issue is that we cannot register WorkflowType with a colon in it (like "MyWorkflow::HelloWorld.sayHello"). Therefore, using Ruby namespaces is excluded.

However, I was able to register a Workflow using backslashes in the name from the console. So that means you can register workflow classes within namespaces using Php. Unfortunately, there is no Php implementation of Flow...

I guess a workaround could be implemented at the SDK level and replace those colons with another separator before registration. And then replace them back when retrieving the WorkflowTypes after polling for tasks.

BTW, the same thing is happening when registering Activities.

trevorrowe commented 10 years ago

The Ruby SDK specifically chooses to not modify user supplied input before sending values to the remote service. This can cause lots of downstream issues where values are not formatted as expected.

I suggest opening this as an issue with the flow framework project. They should be providing SWF friendly values.

trevorrowe commented 10 years ago

Closing this issue for now as there is no SDK changes required.