Class: SWF::ActivityTaskHandler

Inherits:
Object
  • Object
show all
Extended by:
TaskHandler
Defined in:
lib/swf/activity_task_handler.rb

Overview

subclass must call .register(), and define #handle(runner, task)

Constant Summary collapse

@@handler_classes =
Set.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TaskHandler

handle

Constructor Details

#initialize(runner, task) ⇒ ActivityTaskHandler

Returns a new instance of ActivityTaskHandler.



13
14
15
16
# File 'lib/swf/activity_task_handler.rb', line 13

def initialize(runner, task)
  @runner = runner
  @activity_task = task
end

Instance Attribute Details

#activity_taskObject (readonly)

Returns the value of attribute activity_task.



12
13
14
# File 'lib/swf/activity_task_handler.rb', line 12

def activity_task
  @activity_task
end

#runnerObject (readonly)

Returns the value of attribute runner.



12
13
14
# File 'lib/swf/activity_task_handler.rb', line 12

def runner
  @runner
end

Class Method Details

.configuration_help_messageObject



40
41
42
43
# File 'lib/swf/activity_task_handler.rb', line 40

def self.configuration_help_message
  "Each activity task handler running on this task list in this domain must provide a handler class with a handle_* function for this activity_type's name.\n" +
  "I only have these classes: #{@@handler_classes.inspect}"
end

.fail!(task, args = {}) ⇒ Object



31
32
33
# File 'lib/swf/activity_task_handler.rb', line 31

def self.fail!(task, args={})
  task.fail!(args)
end

.find_handler_class(task) ⇒ Object



35
36
37
38
# File 'lib/swf/activity_task_handler.rb', line 35

def self.find_handler_class(task)
  @@handler_classes.find {|x| x.instance_methods.include? handler_method_name task }
  # TODO: detect when two classes define the same named handle_* method ?!?!
end

.handler_method_name(task) ⇒ Object



45
46
47
# File 'lib/swf/activity_task_handler.rb', line 45

def self.handler_method_name(task)
  "handle_#{task.activity_type.name}".to_sym
end

.registerObject

Register statically self (subclass) to handle activities



27
28
29
# File 'lib/swf/activity_task_handler.rb', line 27

def self.register
  @@handler_classes << self
end

Instance Method Details

#activity_task_inputObject



22
23
24
# File 'lib/swf/activity_task_handler.rb', line 22

def activity_task_input
  JSON.parse(activity_task.input)
end

#call_handleObject



18
19
20
# File 'lib/swf/activity_task_handler.rb', line 18

def call_handle
  send self.class.handler_method_name(activity_task)
end