amazon-archives / aws-flow-ruby

ARCHIVED
137 stars 58 forks source link

Workflow starters and Workflow definitions in different apps? #6

Closed Jud closed 10 years ago

Jud commented 10 years ago

The docs are pretty sparse on how one would separate different bits of logic into multiple applications. For instance, if I one batch of servers to start a workflow, the only way I can see to create a workflow client is by:

my_workflow_client = workflow_client($swf.client, $domain) { {:from_class => "BookingWorkflow"} }

This requires that the BookingWorkflow class be available. This seems to apply to Activities as well, since the documented way to create an activity client is to pass in the Activity class. I'd rather not have to include workflow code into the codebase of my 'workflow starters', or Activities code into my workflow codebase, as this would mean that all three groups of servers would require the dependencies of all three different types of workers. What is the best way to accomplish this?

asadj commented 10 years ago

It's not required to have the workflow class available in the starter app (or activity classes available in your workflow code). The from_class option for specifying options is just a convenience method for copying settings from the workflow/activity definition. You can explicitly pass the options instead of copying them from the class, for example in the Booking sample the starter can be modified to create the workflow client like this:

my_workflow_client = workflow_client($swf.client, $domain) do { :prefix_name => "BookingWorkflow", :execution_method => "make_booking", :version => "1.0", :task_list => $workflow_task_list, :execution_start_to_close_timeout => 120 } end

We will clarify this in the documentation.

Jud commented 10 years ago

@asadj Is there some documentation that describes what options are required for each client type?

asadj commented 10 years ago

Unfortunately our documentation for this is not comprehensive. You can find the list of options and defaults here: https://docs.aws.amazon.com/amazonswf/latest/awsrbflowapi/AWS/Flow/WorkflowOptions.html https://docs.aws.amazon.com/amazonswf/latest/awsrbflowapi/AWS/Flow/ActivityOptions.html https://docs.aws.amazon.com/amazonswf/latest/awsrbflowapi/AWS/Flow/StartWorkflowOptions.html https://docs.aws.amazon.com/amazonswf/latest/awsrbflowapi/AWS/Flow/ActivityRuntimeOptions.html https://docs.aws.amazon.com/amazonswf/latest/awsrbflowapi/AWS/Flow/ActivityDefaults.html https://docs.aws.amazon.com/amazonswf/latest/awsrbflowapi/AWS/Flow/WorkflowDefaults.html

Note that you can specify options when you create the client or when you call the activity/workflow. If you specify an option in both places then the most specific one is used. Also when you create workflow or activity type, you can specify some default_xxx options that are registered with the type in SWF and will be used by SWF if the option is not specified by the client.

You can see what params SWF requires for starting a workflow execution here (the options you set translate to these params): http://docs.aws.amazon.com/amazonswf/latest/apireference/API_StartWorkflowExecution.html

and for scheduling an activity: http://docs.aws.amazon.com/amazonswf/latest/apireference/API_ScheduleActivityTaskDecisionAttributes.html

We will improve our documentation clarify this.

Jud commented 10 years ago

@asadj I have a very simple test that I am working on that doesn't use :from_class => ClassName.

https://gist.github.com/Jud/389f24813d1e4042fb57

Whenever I start a workflow, I get the following error:

An exception occurred running workers/request_workflow_worker.rb
    Fiber.new requires a block (ArgumentError)

Any ideas on this error?

asadj commented 10 years ago

I tried running your test locally and I don't see this error. Can you double check that the code in the test is the same as the one that produces this error?

I did find one problem in your test though. When I ran the workflow, the activity failed because the activity type name used by the client did not match the name that was registered by the worker. This is because you are missing prefix_name in the client. The type names Flow uses are of the form: prefix.name. By default it uses the name of the class as 'prefix' and the method name as the 'name' to create the activity name. So the 'setup' activity in your example will be registered by the worker as: TestActivities.setup. Adding :prefix_name => "TestActivities" in test_workflow.rb should fix that:

  activity_client :activity_client do
    {
      :prefix_name => "TestActivities",
      :task_list => REQUEST_ACTIVITY_TASK_LIST.to_s,
      :start_to_close_timeout => 120,
      :version => "1.0",
    }
  end
Jud commented 10 years ago

@asadj Thanks for the info about prefix_name. I checkout out:

https://docs.aws.amazon.com/amazonswf/latest/awsrbflowapi/AWS/Flow/ActivityOptions.html

but didn't see anything about :prefix_name.

The Fiber error ended up being a problem with Rubinius. Thanks for all your help!