Class: Wakame::Command::ActionStatus

Inherits:
Object
  • Object
show all
Includes:
Wakame::Command
Defined in:
lib/wakame/command/action_status.rb

Constant Summary collapse

ACTION_STATUS_TMPL =
<<__E__
Running Actions : <%= @status.size %> action(s)
<%- if @status.size > 0 -%>
<%- @status.each { |id, j| -%>
JOB <%= id %> :
  start : <%= j[:created_at] %>
  <%= tree_subactions(j[:root_action]) %>
<%- } -%>
<%- end -%>
__E__

Instance Method Summary collapse

Methods included from Wakame::Command

included

Instance Method Details

#parse(args) ⇒ Object



19
20
# File 'lib/wakame/command/action_status.rb', line 19

def parse(args)
end


45
46
47
# File 'lib/wakame/command/action_status.rb', line 45

def print_result
  puts ERB.new(ACTION_STATUS_TMPL, nil, '-').result(binding)
end

#run(rule) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/wakame/command/action_status.rb', line 22

def run(rule)
  walk_subactions = proc { |a, level|
    res = a.dump_attrs
    unless a.subactions.empty?
      res[:subactions] = a.subactions.collect { |s|
        walk_subactions.call(s, level + 1)
      }
    end
    res
  }
  
  EM.barrier {
    result = {}
    rule.master.service_cluster.rule_engine.active_jobs.each { |id, v|
      result[id]={:actions=>[], :created_at=>v[:created_at], :src_rule=>v[:src_rule].class.to_s}
      
      result[id][:root_action] = walk_subactions.call(v[:root_action], 0)
    }
    
    @status = result
  }
end