Module: Chore::FilesystemQueue

Included in:
Queues::Filesystem::Consumer, Queues::Filesystem::Publisher
Defined in:
lib/chore/queues/filesystem/filesystem_queue.rb

Overview

Common methods used by FilesystemConsumer and FilesystemPublisher for dealing with the directories which implement the queue.

Constant Summary collapse

NEW_JOB_DIR =

Local directory for new jobs to be placed

"new"
IN_PROGRESS_DIR =

Local directory for jobs currently in-process to be moved

"inprogress"
CONFIG_DIR =

Local directory for configuration info

"config"

Instance Method Summary collapse

Instance Method Details

#config_dir(queue_name) ⇒ Object

The configuration for the given queue



35
36
37
# File 'lib/chore/queues/filesystem/filesystem_queue.rb', line 35

def config_dir(queue_name)
  validate_dir(queue_name, CONFIG_DIR)
end

#config_value(queue_name, config_name) ⇒ Object



39
40
41
42
43
44
# File 'lib/chore/queues/filesystem/filesystem_queue.rb', line 39

def config_value(queue_name, config_name)
  config_file = File.join(config_dir(queue_name), config_name)
  if File.exists?(config_file)
    File.read(config_file).strip
  end
end

#in_progress_dir(queue_name) ⇒ Object

Retrieves the directory for in-process messages to go. If the directory for the queue_name doesn't exist, it will be created for you. If the directory cannot be created, an IOError will be raised



14
15
16
# File 'lib/chore/queues/filesystem/filesystem_queue.rb', line 14

def in_progress_dir(queue_name)
  validate_dir(queue_name, IN_PROGRESS_DIR)
end

#new_dir(queue_name) ⇒ Object

Retrieves the directory for newly recieved messages to go. If the directory for the queue_name doesn't exist, it will be created for you. If the directory cannot be created, an IOError will be raised



20
21
22
# File 'lib/chore/queues/filesystem/filesystem_queue.rb', line 20

def new_dir(queue_name)
  validate_dir(queue_name, NEW_JOB_DIR)
end

#queue_dir(queue_name) ⇒ Object

Returns the fully qualified path to the directory for queue_name



30
31
32
# File 'lib/chore/queues/filesystem/filesystem_queue.rb', line 30

def queue_dir(queue_name)
  prepare_dir(File.join(root_dir, queue_name))
end

#queue_timeout(queue_name) ⇒ Object

Returns the timeout for queue_name



47
48
49
# File 'lib/chore/queues/filesystem/filesystem_queue.rb', line 47

def queue_timeout(queue_name)
  (config_value(queue_name, 'timeout') || Chore.config.default_queue_timeout).to_i
end

#root_dirObject

Returns the root directory where messages are placed



25
26
27
# File 'lib/chore/queues/filesystem/filesystem_queue.rb', line 25

def root_dir
  @root_dir ||= prepare_dir(File.expand_path(Chore.config.fs_queue_root))
end