module Procrastinator::Queue::QueueValidation

Internal queue validator

Private Instance Methods

validate!() click to toggle source
# File lib/procrastinator/queue.rb, line 169
def validate!
   verify_task_class!
   verify_task_store!
end
verify_accessors!() click to toggle source
# File lib/procrastinator/queue.rb, line 194
         def verify_accessors!
            [:logger, :container, :scheduler].each do |method_name|
               next if @task_class.method_defined?(method_name) && @task_class.method_defined?("#{ method_name }=")

               raise MalformedTaskError, <<~ERR
                  Task handler is missing a #{ method_name } accessor. Add this to the #{ @task_class } class definition:
                     attr_accessor :logger, :container, :scheduler
               ERR
            end
         end
verify_hooks!() click to toggle source
# File lib/procrastinator/queue.rb, line 205
def verify_hooks!
   expected_arity = 1

   [:success, :fail, :final_fail].each do |method_name|
      next unless @task_class.method_defined?(method_name)
      next if @task_class.instance_method(method_name).arity == expected_arity

      err = "task #{ @task_class } must accept #{ expected_arity } parameter to its ##{ method_name } method"

      raise MalformedTaskError, err
   end
end
verify_run_method!() click to toggle source

The interface compliance is checked on init because it’s one of those rare cases where you want to know early; otherwise, you wouldn’t know until task execution and that could be far in the future. UX is important for devs, too.

- R
# File lib/procrastinator/queue.rb, line 184
def verify_run_method!
   unless @task_class.method_defined? :run
      raise MalformedTaskError, "task #{ @task_class } does not support #run method"
   end

   return unless @task_class.instance_method(:run).arity.positive?

   raise MalformedTaskError, "task #{ @task_class } cannot require parameters to its #run method"
end
verify_task_class!() click to toggle source
# File lib/procrastinator/queue.rb, line 174
def verify_task_class!
   verify_run_method!
   verify_accessors!
   verify_hooks!
end
verify_task_store!() click to toggle source
# File lib/procrastinator/queue.rb, line 218
def verify_task_store!
   raise ArgumentError, ':store cannot be nil' if @task_store.nil?

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