module Procrastinator::Config::DSL

Collection of all of the methods intended for use within Procrastinator.setup

@see Procrastinator

Public Instance Methods

define_queue(name, task_class, properties = {}) click to toggle source
# File lib/procrastinator/config.rb, line 83
def define_queue(name, task_class, properties = {})
   raise ArgumentError, 'queue name cannot be nil' if name.nil?
   raise ArgumentError, 'queue task class cannot be nil' if task_class.nil?

   verify_task_class(task_class)

   @queues << Queue.new(properties.merge(name: name, task_class: task_class))
end
each_process(prefix: nil, pid_dir: DEFAULT_PID_DIRECTORY, &block) click to toggle source

Accepts a block that will be executed on the queue sub-processes. Use it to control resource allocations.

# File lib/procrastinator/config.rb, line 77
def each_process(prefix: nil, pid_dir: DEFAULT_PID_DIRECTORY, &block)
   @prefix           = prefix
   @subprocess_block = block
   @pid_dir          = Pathname.new(pid_dir)
end
enable_test_mode() click to toggle source
# File lib/procrastinator/config.rb, line 92
def enable_test_mode
   @test_mode = true
end
load_with(loader) click to toggle source

Assigns a task loader It should be called in an each_process block as well so that they get distinct resources (eg. DB connections) from the parent process.

# File lib/procrastinator/config.rb, line 52
def load_with(loader)
   if loader.is_a? Hash
      unless loader.key? :location
         raise ArgumentError, 'Must pass keyword :location if specifying a location for CSV file'
      end

      loader = Loader::CSVLoader.new(loader[:location])
   end

   raise MalformedTaskLoaderError, 'task loader cannot be nil' if loader.nil?

   [:read, :create, :update, :delete].each do |method|
      unless loader.respond_to? method
         raise MalformedTaskLoaderError, "task loader #{ loader.class } must respond to ##{ method }"
      end
   end

   @loader = loader
end
log_at_level(lvl) click to toggle source
# File lib/procrastinator/config.rb, line 100
def log_at_level(lvl)
   @log_level = lvl
end
log_inside(path) click to toggle source
# File lib/procrastinator/config.rb, line 96
def log_inside(path)
   @log_dir = path ? Pathname.new(path) : path
end
provide_context(context) click to toggle source
# File lib/procrastinator/config.rb, line 72
def provide_context(context)
   @context = context
end