Class: JFlow::Activity::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/jflow/activity/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#taskObject (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.message}"
  swf_client.respond_activity_task_failed({
    task_token: token,
    reason: exception.message,
    details: exception.backtrace ? exception.backtrace.join("\n") : "no stacktrace",
  })
end

#inputObject



11
12
13
# File 'lib/jflow/activity/task.rb', line 11

def input
  YAML.load(task.input)
end

#klassObject



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

#methodObject



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

#nameObject



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_idObject



27
28
29
# File 'lib/jflow/activity/task.rb', line 27

def run_id
  task.workflow_execution.run_id
end

#tokenObject



23
24
25
# File 'lib/jflow/activity/task.rb', line 23

def token
  task.task_token
end

#versionObject



19
20
21
# File 'lib/jflow/activity/task.rb', line 19

def version
  task.activity_type.version
end

#workflow_idObject



31
32
33
# File 'lib/jflow/activity/task.rb', line 31

def workflow_id
  task.workflow_execution.workflow_id
end