Class: Ticket
- Inherits:
-
Object
show all
- Includes:
- RedisKey
- Defined in:
- lib/concurrent/ticket.rb
Instance Method Summary
collapse
Methods included from RedisKey
#blocking_key, #client_key, #executing_key
Constructor Details
#initialize(uniq_tag) ⇒ Ticket
uniq_tag desc:
The concurrent objects who point to same reference,
or represent same row in database must use same uniq_tag.
NOTICE:
We have to thing the different databases use the same table name and have the same row id,
so if we use the in multi database for control concurrence we have to specify database's uniq tag.
16
17
18
|
# File 'lib/concurrent/ticket.rb', line 16
def initialize(uniq_tag)
@uniq_tag = uniq_tag
end
|
Instance Method Details
#blocking ⇒ Object
24
25
26
|
# File 'lib/concurrent/ticket.rb', line 24
def blocking
redis.lpush blocking_key, @uniq_tag
end
|
#dispatch ⇒ Object
20
21
22
|
# File 'lib/concurrent/ticket.rb', line 20
def dispatch
executing ? push_to_client : blocking
end
|
#executing ⇒ Object
32
33
34
|
# File 'lib/concurrent/ticket.rb', line 32
def executing
redis.sadd executing_key, @uniq_tag
end
|
#notify ⇒ Object
44
45
46
|
# File 'lib/concurrent/ticket.rb', line 44
def notify
pop_blocking ? push_to_client : rem_executing
end
|
#pop_blocking ⇒ Object
28
29
30
|
# File 'lib/concurrent/ticket.rb', line 28
def pop_blocking
redis.lpop blocking_key
end
|
#push_to_client ⇒ Object
40
41
42
|
# File 'lib/concurrent/ticket.rb', line 40
def push_to_client
redis.lpush client_key, @uniq_tag
end
|
#redis ⇒ Object
48
49
50
|
# File 'lib/concurrent/ticket.rb', line 48
def redis
Concurrent.redis
end
|
#rem_executing ⇒ Object
36
37
38
|
# File 'lib/concurrent/ticket.rb', line 36
def rem_executing
redis.srem executing_key, @uniq_tag
end
|