Class: JFlow::Activity::Task
- Inherits:
-
Object
- Object
- JFlow::Activity::Task
- Defined in:
- lib/jflow/activity/task.rb
Instance Attribute Summary collapse
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Instance Method Summary collapse
- #completed!(result) ⇒ Object
- #failed!(exception) ⇒ Object
-
#initialize(task) ⇒ Task
constructor
A new instance of Task.
- #input ⇒ Object
- #klass ⇒ Object
- #method ⇒ Object
- #name ⇒ Object
- #run! ⇒ Object
- #run_id ⇒ Object
- #token ⇒ Object
- #version ⇒ Object
- #workflow_id ⇒ Object
Constructor Details
#initialize(task) ⇒ Task
Returns a new instance of Task.
7 8 9 |
# File 'lib/jflow/activity/task.rb', line 7 def initialize(task) @task = task end |
Instance Attribute Details
#task ⇒ Object (readonly)
Returns the value of attribute task.
5 6 7 |
# File 'lib/jflow/activity/task.rb', line 5 def task @task end |
Instance Method Details
#completed!(result) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/jflow/activity/task.rb', line 57 def completed!(result) log "Task Completed" swf_client.respond_activity_task_completed({ task_token: token, result: result, }) end |
#failed!(exception) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/jflow/activity/task.rb', line 66 def failed!(exception) log "Task Failed #{exception.}" swf_client.respond_activity_task_failed({ task_token: token, reason: exception., details: exception.backtrace ? exception.backtrace.join("\n") : "no stacktrace", }) end |
#input ⇒ Object
11 12 13 |
# File 'lib/jflow/activity/task.rb', line 11 def input YAML.load(task.input) end |
#klass ⇒ Object
35 36 37 38 39 |
# File 'lib/jflow/activity/task.rb', line 35 def klass @klass_value ||= JFlow.configuration.activity_map.klass_for(name,version) raise "Could not find code to run for given activity" unless @klass_value @klass_value end |
#method ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/jflow/activity/task.rb', line 41 def method if name.split('.').size > 1 method = name.split('.').last else method = "process" end end |
#name ⇒ Object
15 16 17 |
# File 'lib/jflow/activity/task.rb', line 15 def name task.activity_type.name end |
#run! ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/jflow/activity/task.rb', line 49 def run! log "Started #{klass}##{method} with #{input}" result = klass.new.send(method, *input) || "done" log "Result is #{result.class} #{result}" completed!(result) end |
#run_id ⇒ Object
27 28 29 |
# File 'lib/jflow/activity/task.rb', line 27 def run_id task.workflow_execution.run_id end |
#token ⇒ Object
23 24 25 |
# File 'lib/jflow/activity/task.rb', line 23 def token task.task_token end |
#version ⇒ Object
19 20 21 |
# File 'lib/jflow/activity/task.rb', line 19 def version task.activity_type.version end |
#workflow_id ⇒ Object
31 32 33 |
# File 'lib/jflow/activity/task.rb', line 31 def workflow_id task.workflow_execution.workflow_id end |