module Chore::FilesystemQueue
Common methods used by FilesystemConsumer and FilesystemPublisher for dealing with the directories which implement the queue.
Constants
- CONFIG_DIR
Local directory for configuration info
- IN_PROGRESS_DIR
Local directory for jobs currently in-process to be moved
- NEW_JOB_DIR
Local directory for new jobs to be placed
Public Instance Methods
The configuration for the given queue
# File lib/chore/queues/filesystem/filesystem_queue.rb, line 35 def config_dir(queue_name) validate_dir(queue_name, CONFIG_DIR) end
# 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
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
# File lib/chore/queues/filesystem/filesystem_queue.rb, line 14 def in_progress_dir(queue_name) validate_dir(queue_name, IN_PROGRESS_DIR) end
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
# File lib/chore/queues/filesystem/filesystem_queue.rb, line 20 def new_dir(queue_name) validate_dir(queue_name, NEW_JOB_DIR) end
Returns the fully qualified path to the directory for queue_name
# File lib/chore/queues/filesystem/filesystem_queue.rb, line 30 def queue_dir(queue_name) prepare_dir(File.join(root_dir, queue_name)) end
Returns the timeout for queue_name
# 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
Returns the root directory where messages are placed
# 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
Private Instance Methods
Creates a directory if it does not exist. Returns the directory
# File lib/chore/queues/filesystem/filesystem_queue.rb, line 59 def prepare_dir(dir) unless Dir.exists?(dir) FileUtils.mkdir_p(dir) end raise IOError.new("directory for file system queue does not have write permission: #{dir}") unless File.writable?(dir) dir end
Returns the directory for the given queue_name
and task_state
. If the directory doesn't exist, it will be created for you. If the directory cannot be created, an IOError will be raised
# File lib/chore/queues/filesystem/filesystem_queue.rb, line 54 def validate_dir(queue_name, task_state) prepare_dir(File.join(queue_dir(queue_name), task_state)) end