Module: Procrastinator::Config::DSL

Included in:
Procrastinator::Config
Defined in:
lib/procrastinator/config.rb

Overview

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

See Also:

Instance Method Summary collapse

Instance Method Details

#adjust_priority(new_priority) ⇒ Object Also known as: adjust_nice

Sets the desired process ‘nice’ priority value adjustment. This value is added to whatever runtime priority Procrastinator starts with.

Higher numbers are more nice to other processes (lower priority); think of it as the position in line. You can be more nice, but never less nice.



143
144
145
# File 'lib/procrastinator/config.rb', line 143

def adjust_priority(new_priority)
   @priority = new_priority
end

#define_queue(name, task_class, properties = {}) ⇒ Object

Defines a queue in the Procrastinator Scheduler.

The Task Handler will be initialized for each task and assigned each of these attributes:

:container, :logger, :scheduler

Options Hash (properties):

  • :store (Object) — default: Procrastinator::TaskStore::SimpleCommaStore

    Storage strategy for tasks in the queue.

  • :max_attempts (Integer) — default: Procrastinator::Queue::DEFAULT_MAX_ATTEMPTS

    Maximum number of times a task may be attempted before giving up.

  • :timeout (Integer) — default: Procrastinator::Queue::DEFAULT_TIMEOUT

    Maximum number of seconds to wait for a single task to complete.

  • :update_period (Integer) — default: Procrastinator::Queue::DEFAULT_UPDATE_PERIOD

    Time to wait before checking for new tasks.

Raises:

  • (ArgumentError)


112
113
114
115
116
117
118
119
120
121
# File 'lib/procrastinator/config.rb', line 112

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?

   properties[:store] = interpret_store(properties[:store]) if properties.key? :store

   args = {name: name, task_class: task_class, store: @default_store}.merge(properties)

   @queues << Queue.new(**args)
end

#log_with(directory: @log_dir, level: @log_level, shift_age: @log_shift_age, shift_size: @log_shift_size) ⇒ Object

Sets details of logging behaviour



129
130
131
132
133
134
# File 'lib/procrastinator/config.rb', line 129

def log_with(directory: @log_dir, level: @log_level, shift_age: @log_shift_age, shift_size: @log_shift_size)
   @log_dir        = directory ? Pathname.new(directory) : directory
   @log_level      = level
   @log_shift_age  = shift_age
   @log_shift_size = shift_size
end

#provide_container(container) ⇒ Object

Defines the container to assign to each Task Handler’s :container attribute.



92
93
94
# File 'lib/procrastinator/config.rb', line 92

def provide_container(container)
   @container = container
end

#with_store(store) ⇒ Object

Assigns a task loader

Raises:

  • (ArgumentError)


80
81
82
83
84
85
86
87
# File 'lib/procrastinator/config.rb', line 80

def with_store(store)
   raise(ArgumentError, 'with_store must be provided a block') unless block_given?

   old_store      = @default_store
   @default_store = interpret_store(store)
   yield
   @default_store = old_store
end