Class: Gouda::ThreadSafeSet
- Inherits:
-
Object
- Object
- Gouda::ThreadSafeSet
- Defined in:
- lib/gouda/worker.rb
Overview
Is used for keeping the IDs of currently executing jobs on this worker in a thread-safe way. These IDs are used to update the heartbeat timestamps during execution. We need just three methods here - add to a set, remove from a set, and convert the set into an array for a SQL query with ‘WHERE id IN`.
Instance Method Summary collapse
- #add(value) ⇒ Object
- #delete(value) ⇒ Object
-
#initialize ⇒ ThreadSafeSet
constructor
A new instance of ThreadSafeSet.
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ ThreadSafeSet
Returns a new instance of ThreadSafeSet.
14 15 16 17 |
# File 'lib/gouda/worker.rb', line 14 def initialize @set = Set.new @mutex = Mutex.new end |
Instance Method Details
#add(value) ⇒ Object
19 20 21 22 |
# File 'lib/gouda/worker.rb', line 19 def add(value) @mutex.synchronize { @set.add(value) } value end |
#delete(value) ⇒ Object
24 25 26 27 |
# File 'lib/gouda/worker.rb', line 24 def delete(value) @mutex.synchronize { @set.delete(value) } value end |
#to_a ⇒ Object
29 30 31 |
# File 'lib/gouda/worker.rb', line 29 def to_a @mutex.synchronize { @set.to_a } end |