Module: ResqueJobsTree::Storage::Node
Constant Summary
LAUNCHED_TREES, PARENTS_KEY
Instance Method Summary
collapse
Instance Method Details
#childs_key ⇒ Object
27
28
29
|
# File 'lib/resque_jobs_tree/storage/node.rb', line 27
def childs_key
"#{key}:childs"
end
|
#cleanup ⇒ Object
18
19
20
21
22
23
24
25
|
# 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? ⇒ Boolean
54
55
56
57
58
59
60
|
# 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 ⇒ Object
31
32
33
|
# File 'lib/resque_jobs_tree/storage/node.rb', line 31
def key
"ResqueJobsTree:Node:#{serialize}"
end
|
#lock_key ⇒ Object
50
51
52
|
# File 'lib/resque_jobs_tree/storage/node.rb', line 50
def lock_key
"#{key}:lock"
end
|
#only_stored_child? ⇒ Boolean
35
36
37
|
# File 'lib/resque_jobs_tree/storage/node.rb', line 35
def only_stored_child?
(redis.smembers(parent.childs_key) - [key]).empty?
end
|
#parent ⇒ Object
46
47
48
|
# 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 ⇒ Object
4
5
6
7
8
9
10
11
|
# 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 ⇒ Object
39
40
41
42
43
44
|
# 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 ⇒ Object
13
14
15
16
|
# File 'lib/resque_jobs_tree/storage/node.rb', line 13
def unstore
redis.srem parent.childs_key, key
redis.hdel PARENTS_KEY, key
end
|