module Que::Scheduler::VersionSupport

Constants

RETRY_PROC

Public Class Methods

apply_retry_semantics(context) click to toggle source

Ensure the job runs at least once an hour when it is backing off due to errors

# File lib/que/scheduler/version_support.rb, line 25
def apply_retry_semantics(context)
  if zero_major?
    context.instance_variable_set("@retry_interval", RETRY_PROC)
  else
    context.maximum_retry_count = 1 << 128 # Heat death of universe
    context.retry_interval = RETRY_PROC
  end
end
default_scheduler_queue() click to toggle source
# File lib/que/scheduler/version_support.rb, line 50
def default_scheduler_queue
  zero_major? ? "" : Que::DEFAULT_QUEUE
end
execute(str, args = []) click to toggle source

Between Que 0.x and 1.x the result of Que execute changed keys from strings to symbols. Here we wrap the concept and make sure either way produces symbols

# File lib/que/scheduler/version_support.rb, line 46
def execute(str, args = [])
  normalise_array_of_hashes(Que.execute(str, args))
end
job_attributes(enqueued_job) click to toggle source
# File lib/que/scheduler/version_support.rb, line 34
def job_attributes(enqueued_job)
  if zero_major?
    enqueued_job.attrs.to_h.transform_keys(&:to_sym)
  else
    enqueued_job.que_attrs.to_h.transform_keys(&:to_sym).tap do |hash|
      hash[:job_id] = hash.delete(:id)
    end
  end
end
que_version() click to toggle source
# File lib/que/scheduler/version_support.rb, line 67
def que_version
  @que_version ||= Gem.loaded_specs["que"].version.to_s
end
running_synchronously?() click to toggle source
# File lib/que/scheduler/version_support.rb, line 54
def running_synchronously?
  zero_major? ? (Que.mode == :sync) : Que.run_synchronously
end
running_synchronously_code?() click to toggle source
# File lib/que/scheduler/version_support.rb, line 58
def running_synchronously_code?
  zero_major? ? "Que.mode == :sync" : "Que.run_synchronously = true"
end
set_priority(context, priority) click to toggle source

Ensure que-scheduler runs at the highest priority. This is because its priority is a the top of all jobs it enqueues.

# File lib/que/scheduler/version_support.rb, line 16
def set_priority(context, priority)
  if zero_major?
    context.instance_variable_set("@priority", priority)
  else
    context.priority = priority
  end
end
zero_major?() click to toggle source
# File lib/que/scheduler/version_support.rb, line 62
def zero_major?
  # This is the only way to handle beta releases too
  @zero_major ||= que_version.split(".").first.to_i.zero?
end

Private Class Methods

normalise_array_of_hashes(array) click to toggle source
# File lib/que/scheduler/version_support.rb, line 73
def normalise_array_of_hashes(array)
  array.map { |row| row.to_h.transform_keys(&:to_sym) }
end