class ResqueJobsTree::Node
Attributes
definition[R]
resources[R]
tree[R]
Public Class Methods
new(definition, resources, parent=nil, tree=nil)
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 7 def initialize definition, resources, parent=nil, tree=nil @childs = [] @definition = definition @resources = resources @parent = parent @tree = tree end
Public Instance Methods
after_perform()
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 27 def after_perform run_callback :after_perform if root? tree.finish else lock do parent.enqueue if only_stored_child? unstore end end end
before_perform()
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 23 def before_perform run_callback :before_perform end
childs()
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 69 def childs return @childs unless @childs.empty? @childs = definition.leaf? ? [] : definition.childs.call(*resources) end
enqueue()
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 15 def enqueue Resque.enqueue_to definition.tree.name, ResqueJobsTree::Job, *argumentize end
inspect()
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 86 def inspect "<ResqueJobsTree::Node @name=#{name} @resources=#{resources}>" end
leaf?()
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 57 def leaf? childs.empty? end
name()
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 53 def name definition.name end
on_failure()
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 39 def on_failure if definition.options[:continue_on_failure] run_callback :on_failure after_perform else root.tree.on_failure root.cleanup end end
perform()
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 19 def perform definition.perform.call *resources end
register()
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 74 def register store unless root? if leaf? tree.register_node self else childs.each do |node_name, *resources| node = definition.find(node_name).spawn resources, self node.register end end end
root()
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 65 def root @root ||= root? ? self : parent.root end
root?()
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 61 def root? definition.root? end
Private Instance Methods
run_callback(callback)
click to toggle source
# File lib/resque_jobs_tree/node.rb, line 92 def run_callback callback callback_block = definition.send callback callback_block.call(*resources) if callback_block.kind_of? Proc rescue if [:after_perform, :on_failure].include? callback puts "[ResqueJobsTree::Tree] after_perform callback of node #{definition.tree.name}##{name} has failed."\ " Continuing for cleanup." else raise end end