Class: WFlow::NodeWorker

Inherits:
Object
  • Object
show all
Defined in:
lib/w_flow/node_worker.rb

Instance Method Summary collapse

Constructor Details

#initialize(owner_process, node_class) ⇒ NodeWorker

Returns a new instance of NodeWorker.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/w_flow/node_worker.rb', line 4

def initialize(owner_process, node_class)
  @owner_process = owner_process
  @tasks   = node_class.tasks

  options  = node_class.options

  @execute_if      = options[:if]
  @execute_unless  = options[:unless]
  @around_proc     = options[:around]
  @confirm_stop    = options[:stop]
  @confirm_failure = options[:failure]
end

Instance Method Details

#execute?Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/w_flow/node_worker.rb', line 17

def execute?
  (@execute_if.nil?     || process_eval(@execute_if)) &&
  (@execute_unless.nil? || !process_eval(@execute_unless))
end

#finalizeObject



50
51
52
# File 'lib/w_flow/node_worker.rb', line 50

def finalize
  executed_do(:finalize)
end

#process_eval(object, *args) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/w_flow/node_worker.rb', line 58

def process_eval(object, *args)
  if object.is_a?(String) || object.is_a?(Symbol)
    @owner_process.send(object.to_s, *args)
  elsif object.is_a?(Proc)
    @owner_process.instance_exec(*args, &object)
  else
    raise InvalidArguments, UNKNOWN_EXPRESSION
  end
end

#rollbackObject



54
55
56
# File 'lib/w_flow/node_worker.rb', line 54

def rollback
  executed_do(:rollback)
end

#run(flow) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/w_flow/node_worker.rb', line 22

def run(flow)
  @flow = flow
  @executed_tasks_workers = []

  report = Supervisor.supervise do
    if @around_proc.nil?
      execute_tasks
    else
      process_eval(@around_proc, method(:execute_tasks))
    end
  end

  if report.failed?
    rollback
    finalize

    @executed_tasks_workers.clear

    if signal_failure?
      Supervisor.resignal!(report)
    else
      @flow.log_failure(report.message)
    end
  elsif report.stopped? && signal_stop?
    Supervisor.resignal!(report)
  end
end