48. Rubyで始めるSWF
事前に見ておくもの
Getting Started with AWS Flow Framework for Ruby for Amazon SWF
https://www.youtube.com/watch?v=Z_dvXy4AVEE
準備するもの
AWSのAccessKeyIDとSecretAccessKey
Rubyの実行環境
Gemのダウンロード
55. ワークフロー
require_relative 'utils'
require_relative "./hello_activity"
class HelloWorldWorkflow
extend AWS::Flow::Workflows
workflow :hello_workflow do
{
:version => "1", :execution_start_to_close_timeout => 3600, :task_list => $TASK_LIST
}
end
activity_client(:activity) { {:from_class => "HelloWorldActivity"} }
def hello_workflow(name)
activity.hello_activity(name)
end
end
worker = AWS::Flow::WorkflowWorker.new($SWF.client, $HELLOWORLD_DOMAIN, $TASK_LIST,
HelloWorldWorkflow)
# Start the worker if this file is called directly from the command line.
worker.start if __FILE__ == $0
hello_workflow.rb
呼び出すアクティビティの設定
ワークフローの設定
56. アクティビティ
require_relative 'utils'
class HelloWorldActivity
extend AWS::Flow::Activities
activity :hello_activity do
{
:default_task_list => $TASK_LIST, :version => "my_first_activity",
:default_task_schedule_to_start_timeout => 30,
:default_task_start_to_close_timeout => 30
}
end
def hello_activity(name)
puts "Hello, #{name}!"
end
end
activity_worker = AWS::Flow::ActivityWorker.new($SWF.client, $HELLOWORLD_DOMAIN,
$TASK_LIST, HelloWorldActivity) { {:use_forking => false} }
# Start the worker if this file is called directly from the command line.
activity_worker.start if __FILE__ == $0
hello_activity.rb
57. アクティビティ
require_relative 'utils'
class HelloWorldActivity
extend AWS::Flow::Activities
activity :hello_activity do
{
:default_task_list => $TASK_LIST, :version => "my_first_activity",
:default_task_schedule_to_start_timeout => 30,
:default_task_start_to_close_timeout => 30
}
end
def hello_activity(name)
puts "Hello, #{name}!"
end
end
activity_worker = AWS::Flow::ActivityWorker.new($SWF.client, $HELLOWORLD_DOMAIN,
$TASK_LIST, HelloWorldActivity) { {:use_forking => false} }
# Start the worker if this file is called directly from the command line.
activity_worker.start if __FILE__ == $0
hello_activity.rb
アクティビティの設定
58. アクティビティ
require_relative 'utils'
class HelloWorldActivity
extend AWS::Flow::Activities
activity :hello_activity do
{
:default_task_list => $TASK_LIST, :version => "my_first_activity",
:default_task_schedule_to_start_timeout => 30,
:default_task_start_to_close_timeout => 30
}
end
def hello_activity(name)
puts "Hello, #{name}!"
end
end
activity_worker = AWS::Flow::ActivityWorker.new($SWF.client, $HELLOWORLD_DOMAIN,
$TASK_LIST, HelloWorldActivity) { {:use_forking => false} }
# Start the worker if this file is called directly from the command line.
activity_worker.start if __FILE__ == $0
hello_activity.rb
処理内容
アクティビティの設定
59. ワークフロースターター
require 'aws/decider'
require_relative 'utils'
require_relative 'hello_workflow'
# Get a workflow client to start the workflow
my_workflow_client = AWS::Flow.workflow_client($SWF.client, $HELLOWORLD_DOMAIN) do
{:from_class => "HelloWorldWorkflow"}
end
puts "Starting an execution..."
workflow_execution = my_workflow_client.start_execution("AWS Flow Framework for Ruby")
hello_world.rb