module ResqueJobsTree::Storage::Node
Public Instance Methods
childs_key()
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 27 def childs_key "#{key}:childs" end
cleanup()
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 18 def cleanup unless definition.leaf? stored_childs.each &:cleanup redis.del childs_key end redis.hdel PARENTS_KEY, key tree.unstore if root? end
exists?()
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 54 def exists? if definition.root? tree.exists? else redis.exists(childs_key) || redis.hexists(PARENTS_KEY, key) end end
key()
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 31 def key "ResqueJobsTree:Node:#{serialize}" end
lock_key()
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 50 def lock_key "#{key}:lock" end
only_stored_child?()
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 35 def only_stored_child? (redis.smembers(parent.childs_key) - [key]).empty? end
parent()
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 46 def parent @parent ||= definition.parent.spawn node_info_from_key(parent_key).last end
store()
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 4 def store raise 'Can\'t store a root node' if root? redis.hset PARENTS_KEY, key, parent.key unless redis.sadd parent.childs_key, key raise ResqueJobsTree::JobNotUniq, "Job #{parent.name} already has the child #{name} with resources: #{resources}" end end
stored_childs()
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 39 def stored_childs redis.smembers(childs_key).map do |_key| node_name, _resources = node_info_from_key _key definition.find(node_name).spawn _resources end end
unstore()
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 13 def unstore redis.srem parent.childs_key, key redis.hdel PARENTS_KEY, key end
Private Instance Methods
lock() { || ... }
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 64 def lock _key = parent.lock_key while !redis.setnx(_key, 'locked') sleep 0.05 # 50 ms end yield ensure redis.del _key end
main_arguments()
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 84 def main_arguments [definition.tree.name, name] end
node_info_from_key(_key)
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 78 def node_info_from_key _key tree_name, node_name, *resources_arguments = JSON.load(_key.gsub /ResqueJobsTree:Node:/, '') _resources = ResqueJobsTree::ResourcesSerializer.instancize(resources_arguments) [node_name, _resources] end
parent_key()
click to toggle source
# File lib/resque_jobs_tree/storage/node.rb, line 74 def parent_key redis.hget PARENTS_KEY, key end