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.
15 16 17 18 |
# File 'lib/gouda/worker.rb', line 15 def initialize @set = Set.new @mutex = Mutex.new end |
Instance Method Details
#add(value) ⇒ Object
20 21 22 23 |
# File 'lib/gouda/worker.rb', line 20 def add(value) @mutex.synchronize { @set.add(value) } value end |
#delete(value) ⇒ Object
25 26 27 28 |
# File 'lib/gouda/worker.rb', line 25 def delete(value) @mutex.synchronize { @set.delete(value) } value end |
#to_a ⇒ Object
30 31 32 |
# File 'lib/gouda/worker.rb', line 30 def to_a @mutex.synchronize { @set.to_a } end |