Class: JFlow::Activity::Task
- Inherits:
-
Object
- Object
- JFlow::Activity::Task
- Defined in:
- lib/jflow/activity/task.rb
Constant Summary collapse
- MAX_DETAILS_SIZE =
32768
- MAX_REASON_SIZE =
256
- TRUNCATION_IDENTIFIER =
'[TRUNCATED]'
Instance Attribute Summary collapse
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Instance Method Summary collapse
- #completed!(result) ⇒ Object
- #definition_options ⇒ Object
- #failed!(exception) ⇒ Object
- #handle_exception(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.
12 13 14 |
# File 'lib/jflow/activity/task.rb', line 12 def initialize(task) @task = task end |
Instance Attribute Details
#task ⇒ Object (readonly)
Returns the value of attribute task.
10 11 12 |
# File 'lib/jflow/activity/task.rb', line 10 def task @task end |
Instance Method Details
#completed!(result) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/jflow/activity/task.rb', line 68 def completed!(result) log "Task Completed" swf_client.respond_activity_task_completed({ task_token: token, result: result, }) end |
#definition_options ⇒ Object
46 47 48 49 50 |
# File 'lib/jflow/activity/task.rb', line 46 def @definition_options ||= JFlow.configuration.activity_map.(name,version) raise "Could not find activity definition for #{name}, #{version}" unless @definition_options @definition_options end |
#failed!(exception) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/jflow/activity/task.rb', line 76 def failed!(exception) log "Task Failed #{exception.}" reason = truncate(exception., MAX_REASON_SIZE) if retryable?(exception) converted_exception = JFlow::Exceptions::Common.new(exception) else converted_exception = JFlow::Exceptions::Fatal.new(exception) end swf_client.respond_activity_task_failed( task_token: token, reason: reason, details: truncate(YAML.dump_stream(converted_exception, exception.backtrace), MAX_DETAILS_SIZE) ) end |
#handle_exception(exception) ⇒ Object
94 95 96 |
# File 'lib/jflow/activity/task.rb', line 94 def handle_exception(exception) JFlow.handle_exception(exception) end |
#input ⇒ Object
16 17 18 |
# File 'lib/jflow/activity/task.rb', line 16 def input YAML.load(task.input) end |
#klass ⇒ Object
40 41 42 43 44 |
# File 'lib/jflow/activity/task.rb', line 40 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
52 53 54 55 56 57 58 |
# File 'lib/jflow/activity/task.rb', line 52 def method if name.split('.').size > 1 method = name.split('.').last else method = "process" end end |
#name ⇒ Object
20 21 22 |
# File 'lib/jflow/activity/task.rb', line 20 def name task.activity_type.name end |
#run! ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/jflow/activity/task.rb', line 60 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
32 33 34 |
# File 'lib/jflow/activity/task.rb', line 32 def run_id task.workflow_execution.run_id end |
#token ⇒ Object
28 29 30 |
# File 'lib/jflow/activity/task.rb', line 28 def token task.task_token end |
#version ⇒ Object
24 25 26 |
# File 'lib/jflow/activity/task.rb', line 24 def version task.activity_type.version end |
#workflow_id ⇒ Object
36 37 38 |
# File 'lib/jflow/activity/task.rb', line 36 def workflow_id task.workflow_execution.workflow_id end |