module Que

A wrapper around whatever connection pool we’re using. Mainly just asserts that the source connection pool is reentrant and thread-safe.

The class that jobs should generally inherit from.

A sized thread-safe queue that holds ordered job sort_keys. Supports blocking while waiting for a job to become available, only returning jobs over a minimum priority, and stopping gracefully.

A thin wrapper around a job’s data that lets us do things like sort easily and make sure that run_at is in the format we want.

A thread-safe queue that holds ids for jobs that have been worked. Allows appending single/retrieving all ids in a thread-safe fashion.

Assertion helpers. Que has a fair amount of internal state, and there’s no telling what users will try to throw at it, so for ease of debugging issues it makes sense to sanity-check frequently.

Helper method for recursively freezing a data structure.

Tools for introspecting the state of the job queue.

Tools for logging from Que.

Logic for middleware to wrap jobs.

Tools for managing the contents/state of the queue.

A helper method to manage transactions, used mainly by the migration system. It’s available for general use, but if you’re using an ORM that provides its own transaction helper, be sure to use that instead, or the two may interfere with one another.

Constants

CONFIG_MUTEX
CURRENT_HOSTNAME
DEFAULT_QUEUE
MAXIMUM_PRIORITY
SQL

Store SQL strings frozen, with squashed whitespace so logs read better.

TIME_REGEX
VERSION

Attributes

default_queue[W]
locker[RW]
pool[W]

Set the current pool. Helpful for specs, but probably shouldn’t be used generally.

use_prepared_statements[RW]

Global configuration logic.

Public Class Methods

connection=(conn) click to toggle source

Support simple integration with many common connection pools.

# File lib/que.rb, line 87
def connection=(conn)
  self.connection_proc =
    if conn.to_s == 'ActiveRecord'
      # Load and setup AR compatibility.
      require_relative 'que/active_record/connection'
      m = Que::ActiveRecord::Connection::JobMiddleware
      job_middleware << m unless job_middleware.include?(m)
      Que::ActiveRecord::Connection.method(:checkout)
    else
      case conn.class.to_s
      when 'Sequel::Postgres::Database' then conn.method(:synchronize)
      when 'Pond'                       then conn.method(:checkout)
      when 'ConnectionPool'             then conn.method(:with)
      when 'NilClass'                   then conn
      else raise Error, "Unsupported connection: #{conn.class}"
      end
    end
end
connection_proc=(connection_proc) click to toggle source

Integrate Que with any connection pool by passing it a reentrant block that locks and yields a Postgres connection.

# File lib/que.rb, line 108
def connection_proc=(connection_proc)
  @pool = connection_proc && ConnectionPool.new(&connection_proc)
end
default_queue() click to toggle source
# File lib/que.rb, line 78
def default_queue
  @default_queue || DEFAULT_QUEUE
end
job_schema_version() click to toggle source
# File lib/que/version.rb, line 6
def self.job_schema_version
  2
end
pool() click to toggle source

How to actually access Que’s established connection pool.

# File lib/que.rb, line 113
def pool
  @pool || raise(Error, "Que connection not established!")
end
server?() click to toggle source
# File lib/que.rb, line 82
def server?
  !defined?(Que::CommandLineInterface).nil?
end