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

#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)


106
107
108
109
110
111
112
113
# File 'lib/procrastinator/config.rb', line 106

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

   @queues << Queue.new(**{name: name, task_class: task_class, store: @default_store}.merge(properties))
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



121
122
123
124
125
126
# File 'lib/procrastinator/config.rb', line 121

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.



86
87
88
# File 'lib/procrastinator/config.rb', line 86

def provide_container(container)
   @container = container
end

#with_store(store) ⇒ Object

Assigns a task loader

Raises:

  • (ArgumentError)


74
75
76
77
78
79
80
81
# File 'lib/procrastinator/config.rb', line 74

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