fredjean / simpler_workflow

Wrapper for Amazon's Simple Workflow Service
MIT License
41 stars 7 forks source link

Can't get activity to start #5

Open mcorner opened 11 years ago

mcorner commented 11 years ago

Really interesting work. Looking forward to using it. I cobbled together a full example based on the README to try it out, but I must be missing something. I don't see my activity ever run. Example below.

Output: I, [2013-04-19T15:15:18.994277 #1732] INFO -- : Registering Activity[my_activity,1.0.0] I, [2013-04-19T15:15:19.152609 #1733] INFO -- : Starting activity_loop for my_activity I, [2013-04-19T15:15:19.802186 #1734] INFO -- : Waiting for a decision task for my_workflow, 1.0.0 listening to my_workflow I, [2013-04-19T15:16:21.106458 #1734] INFO -- : Waiting for a decision task for my_workflow, 1.0.0 listening to my_workflow I, [2013-04-19T15:17:22.337401 #1734] INFO -- : Waiting for a decision task for my_workflow, 1.0.0 listening to my_workflow . . .

Code:

require 'logger'

$logger = Logger.new(STDOUT)

require 'simpler_workflow' require 'active_support'

config_path = File.expand_path(File.dirname(FILE)+"/aws.yml")

AWS.config(YAML.load(File.read(config_path)))

domain = SimplerWorkflow::Domain["my-domain"]

my_activity = domain.register_activity :my_activity, "1.0.0" do on_fail :retry

perform_activity do |task| logger.info "performing my activity" end end

my_activity.start_activity_loop

my_workflow = domain.register_workflow :my_workflow, '1.0.0' do initial_activity :my_activity, '1.0.0'

on_start_execution do |task, event| logger.info "on_start_execution" task.schedule_activity_task my_activity.to_activity_type, :input => { :my_param => 'value'} end end

my_workflow.decision_loop

fredjean commented 11 years ago

That will start the different loops, but you still need to trigger the workflow with:

SimplerWorkflow::Domain["my-test-domain"].start_workflow("my_workflow", "1.0.0", params)

You look at an example line at https://github.com/fredjean/swf_example/blob/master/lib/tasks/simpler_workflow.rake#L10

One note is that Simple Workflow requires the input for a task to be a string. It will not accept a Hash. You can however call .to_json on it.

fredjean commented 11 years ago

I just realized that I didn't provide information on how to trigger the workflow in the read me. Thank you for opening this issue!

mcorner commented 11 years ago

I will definitely take a look at the example Rails app. In the meantime, I did modify my simple script to start the activity, but I am getting an odd error from AWS.

I, [2013-04-19T15:39:59.850136 #2254] INFO -- : Registering Activity[my_activity,1.0.0] I, [2013-04-19T15:40:00.018360 #2255] INFO -- : Starting activity_loop for my_activity I, [2013-04-19T15:40:00.669358 #2254] INFO -- : Starting workflow[my_workflow,1.0.0] I, [2013-04-19T15:40:00.670128 #2256] INFO -- : Waiting for a decision task for my_workflow, 1.0.0 listening to my_workflow /Users/mcorner/.rvm/gems/ruby-1.9.3-p286/gems/aws-sdk-1.6.9/lib/aws/core/client.rb:318:in return_or_raise': {"__type":"com.amazonaws.swf.base.model#WorkflowExecutionAlreadyStartedFault"} (AWS::SimpleWorkflow::Errors::WorkflowExecutionAlreadyStartedFault) from /Users/mcorner/.rvm/gems/ruby-1.9.3-p286/gems/aws-sdk-1.6.9/lib/aws/core/client.rb:419:inclient_request' from (eval):3:in start_workflow_execution' from /Users/mcorner/.rvm/gems/ruby-1.9.3-p286/gems/aws-sdk-1.6.9/lib/aws/simple_workflow/workflow_type.rb:126:instart_execution' from /Users/mcorner/.rvm/gems/ruby-1.9.3-p286/gems/simpler_workflow-0.2.7/lib/simpler_workflow/workflow.rb:163:in start_workflow' from /Users/mcorner/.rvm/gems/ruby-1.9.3-p286/gems/simpler_workflow-0.2.7/lib/simpler_workflow/domain.rb:46:instart_workflow' from simpler.rb:36:in `

' I, [2013-04-19T15:40:01.319606 #2256] INFO -- : Received decision task I, [2013-04-19T15:40:01.322254 #2256] INFO -- : Processing WorkflowExecutionStarted I, [2013-04-19T15:40:01.322447 #2256] INFO -- : Starting the execution of the job. I, [2013-04-19T15:40:01.322887 #2256] INFO -- : Processing DecisionTaskScheduled I, [2013-04-19T15:40:01.323020 #2256] INFO -- : Processing DecisionTaskStarted I, [2013-04-19T15:40:01.432668 #2256] INFO -- : Waiting for a decision task for my_workflow, 1.0.0 listening to my_workflow I, [2013-04-19T15:41:02.231104 #2256] INFO -- : Waiting for a decision task for my_workflow, 1.0.0 listening to my_workflow I, [2013-04-19T15:42:02.637210 #2256] INFO -- : Waiting for a decision task for my_workflow, 1.0.0 listening to my_workflow

Script:

require 'logger'

$logger = Logger.new(STDOUT)

require 'simpler_workflow' require 'active_support'

config_path = File.expand_path(File.dirname(FILE)+"/aws.yml")

AWS.config(YAML.load(File.read(config_path)))

domain = SimplerWorkflow::Domain["my-domain"]

my_activity = domain.register_activity :my_activity, "1.0.0" do on_fail :retry

perform_activity do |task| logger.info "performing my activity" end end

my_activity.start_activity_loop

my_workflow = domain.register_workflow :my_workflow, '1.0.0' do initial_activity :my_activity, '1.0.0' end

my_workflow.decision_loop

SimplerWorkflow::Domain["my-domain"].start_workflow("my_workflow", "1.0.0", 'my input')

fredjean commented 11 years ago

I'll have a look at it tonight. My guess is that more than one of the forked processes are triggering the workflow. I'll need to try a few things.

One thought would be to split the script in two. One contains the definition of the workflow, the other one contains the code that trigger it.

fredjean commented 11 years ago

I can reproduce this error pretty easily, but I am not quite sure what is causing it. I have added code to catch the errors in for the next version of the gem, but it still doesn't quite explain what is happening.

mcorner commented 11 years ago

I tried the rails app, but I actually never see a decision task show up either (thus no hope of getting an activity either). I can find the workflow registered in the SWF console, but no executions at all. I added this to the register_workflow to help debug:

on_start_execution do |task, event|
  logger.info "Start Execution!!!!"
end

And I never see the log message. But frankly I haven't been able to get this to work via the standard aws gem either: https://forums.aws.amazon.com/thread.jspa?threadID=122497&tstart=0

mcorner commented 11 years ago

Argh, just found it, sorry. I needed to run: bundle exec rake swf:fire

to actually fire it. Plus the domain and the flow version are specified in the setup of the flow as well as in the rake task that fires it.

Slowly getting there :)

fredjean commented 11 years ago

Sounds like you are making progress! :+1:

We need to know the workflow and the version of the workflow so we can get back to SimpleWorkflow and get the right information. There's a lot of code written around that assumption. I have created constants in the past to simplify the lookup of workflows and activities.

I just wrapped it in a rake task to make it easy to test. You can just as well trigger it in your rails app via a call back or inline.

I still want to figure out why it didn't work when called from within the process that defines the activities and workflow. I am puzzled by that one...

mcorner commented 11 years ago

Very, very slowly... I can only find 5 minutes at a time to look at it...

Now I am stuck at the activity poller not picking up the "helllo" activity. I can find it waiting in the SWF console, but the poller doesn't see it. Eventually it times out. Not sure yet....

fredjean commented 11 years ago

Could you post the code that you are working with? A gist would be good enough...

mcorner commented 11 years ago

Sorry, but I have gotten pretty off-topic on the original issue here..

I actually went back to the basics and picked up the raw aws-sdk again. I think one of my underlying problems is with how SWF deals with restarts in decision pollers and activity pollers. (Not well IMHO). It really likes to hand things to dead pids due to long polling, but then doesn't seem to have a great recovery method.

Here is my code: https://gist.github.com/mcorner/5444310

And my question to the AWS forums. https://forums.aws.amazon.com/thread.jspa?messageID=445067&#445067

fredjean commented 11 years ago

I have found a bug within the code that register the activities with SWF. It ended up setting the wrong task list name on the activity_type which would explain why the activity didn't get triggered (if you were using the 0.3.0.beta version of the gem or my repo).

I have pushed the updated code up. You would need to change the version of the affected activities since this is set at registration time and cannot (afaik) be changed.

mcorner commented 11 years ago

Hey, yeah, that works! Nice!

I used this: gem 'simpler_workflow', :git => 'git://github.com/fredjean/simpler_workflow.git', :ref => 'c87cabf'

and the activity runs. Good stuff. Sorry for dragging this github issue in three directions.