Class: DaemonicThreads::Queues
- Inherits:
-
Object
- Object
- DaemonicThreads::Queues
- Defined in:
- lib/ruby-daemonic-threads/queues.rb
Overview
NOTE:
This is not a quarantied delivery queues.
They rely on normal process startup/shutdown sequence.
So, if you got segfault all data will be lost.
On the other hand, queues tends to be quite quickly
Constant Summary collapse
- DEFAULT_STORAGE_DIR =
Rails.root + 'tmp' + 'queues'
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize(process) ⇒ Queues
constructor
A new instance of Queues.
- #restore ⇒ Object
- #store ⇒ Object
Constructor Details
#initialize(process) ⇒ Queues
Returns a new instance of Queues.
27 28 29 30 31 32 33 |
# File 'lib/ruby-daemonic-threads/queues.rb', line 27 def initialize(process) @queues = {} @storage_dir = DEFAULT_STORAGE_DIR @queue_names = process.config.queue_names raise("Queues storage directory #{@storage_dir} is not available!") unless storage_available? end |
Instance Method Details
#[](name) ⇒ Object
53 54 55 |
# File 'lib/ruby-daemonic-threads/queues.rb', line 53 def [] name @queues[name] end |
#restore ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby-daemonic-threads/queues.rb', line 35 def restore @queue_names.each do |name| if File.exists?(filename = "#{@storage_dir}/#{name}") @queues[name] = SmartQueue.new(File.read(filename)) File.unlink(filename) else @queues[name] = SmartQueue.new end @queues[name].persistent = true end end |
#store ⇒ Object
47 48 49 50 51 |
# File 'lib/ruby-daemonic-threads/queues.rb', line 47 def store @queues.each do |name, queue| File.write("#{@storage_dir}/#{name}", queue.to_storage) if queue.persistent end end |