class Procrastinator::Queue

A Queue defines how a certain type task will be processed.

@author Robin Miller

@!attribute [r] :name

@return [Symbol] The queue's identifier symbol

@!attribute [r] :task_class

@return [Class] Class that defines the work to be done for jobs in this queue.

@!attribute [r] :timeout

@return [Object] Duration (seconds) after which tasks in this queue should fail for taking too long.

@!attribute [r] :max_attempts

@return [Object] Maximum number of attempts for tasks in this queue.

@!attribute [r] :update_period

@return [Pathname] Delay (seconds) between reloads of tasks from the task loader.

@!attribute [r] :max_tasks

@return [Pathname] The maximum number of tasks to run concurrently within a queue worker process.

Constants

DEFAULT_MAX_ATTEMPTS
DEFAULT_MAX_TASKS
DEFAULT_TIMEOUT
DEFAULT_UPDATE_PERIOD

Attributes

max_attempts[R]
max_tasks[R]
name[R]
task_class[R]
timeout[R]
update_period[R]

Public Class Methods

new(name:, task_class:, max_attempts: DEFAULT_MAX_ATTEMPTS, timeout: DEFAULT_TIMEOUT, update_period: DEFAULT_UPDATE_PERIOD, max_tasks: DEFAULT_MAX_TASKS) click to toggle source

Timeout is in seconds

# File lib/procrastinator/queue.rb, line 29
def initialize(name:,
               task_class:,
               max_attempts: DEFAULT_MAX_ATTEMPTS,
               timeout: DEFAULT_TIMEOUT,
               update_period: DEFAULT_UPDATE_PERIOD,
               max_tasks: DEFAULT_MAX_TASKS)
   raise ArgumentError, ':name may not be nil' unless name
   raise ArgumentError, ':task_class may not be nil' unless task_class

   raise ArgumentError, 'Task class must be initializable' unless task_class.respond_to? :new

   raise ArgumentError, 'timeout cannot be negative' if timeout&.negative?

   @name          = name.to_s.strip.gsub(/[^A-Za-z0-9]+/, '_').to_sym
   @task_class    = task_class
   @max_attempts  = max_attempts
   @timeout       = timeout
   @update_period = update_period
   @max_tasks     = max_tasks
end