Module: QC

Defined in:
lib/queue_classic/okjson.rb,
lib/queue_classic.rb,
lib/queue_classic/conn.rb,
lib/queue_classic/queue.rb,
lib/queue_classic/setup.rb,
lib/queue_classic/worker.rb,
lib/queue_classic/queries.rb

Overview

Defined Under Namespace

Modules: Conn, OkJson, Queries, Setup Classes: Queue, Worker

Constant Summary collapse

Root =
File.expand_path("..", File.dirname(__FILE__))
SqlFunctions =
File.join(QC::Root, "/sql/ddl.sql")
DropSqlFunctions =
File.join(QC::Root, "/sql/drop_ddl.sql")
CreateTable =
File.join(QC::Root, "/sql/create_table.sql")
TABLE_NAME =

Why do you want to change the table name? Just deal with the default OK? If you do want to change this, you will need to update the PL/pgSQL lock_head() function. Come on. Don’t do it.… Just stick with the default.

"queue_classic_jobs"
QUEUE =

Each row in the table will have a column that notes the queue. You can point your workers at different queues but only one at a time.

ENV["QUEUE"] || "default"
TOP_BOUND =

Set this to 1 for strict FIFO. There is nothing special about 9.…

(ENV["QC_TOP_BOUND"] || 9).to_i
LISTENING_WORKER =

If you are using PostgreSQL > 9 then you will have access to listen/notify with payload. Set this value if you wish to make your worker more efficient.

!ENV["QC_LISTENING_WORKER"].nil?
FORK_WORKER =

Set this variable if you wish for the worker to fork a UNIX process for each locked job. Remember to re-establish any database connections. See the worker for more details.

!ENV["QC_FORK_WORKER"].nil?
MAX_LOCK_ATTEMPTS =

The worker uses an exponential back-off algorithm to lock a job. This value will be used as the max exponent.

(ENV["QC_MAX_LOCK_ATTEMPTS"] || 5).to_i

Class Method Summary collapse

Class Method Details

.default_queueObject



69
70
71
72
73
# File 'lib/queue_classic.rb', line 69

def self.default_queue
  @default_queue ||= begin
    Queue.new(QUEUE)
  end
end

.log(data) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/queue_classic.rb', line 88

def self.log(data)
  result = nil
  data = {:lib => "queue-classic"}.merge(data)
  if block_given?
    start = Time.now
    result = yield
    data.merge(:elapsed => Time.now - start)
  end
  data.reduce(out=String.new) do |s, tup|
    s << [tup.first, tup.last].join("=") << " "
  end
  puts(out) if ENV["DEBUG"]
  return result
end

.log_yield(data) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/queue_classic.rb', line 75

def self.log_yield(data)
  begin
    t0 = Time.now
    yield
  rescue => e
    log({:at => "error", :error => e.inspect}.merge(data))
    raise
  ensure
    t = Integer((Time.now - t0)*1000)
    log(data.merge(:elapsed => t)) unless e
  end
end

.method_missing(sym, *args, &block) ⇒ Object

Defer method calls on the QC module to the default queue. This facilitates QC.enqueue()



60
61
62
# File 'lib/queue_classic.rb', line 60

def self.method_missing(sym, *args, &block)
  default_queue.send(sym, *args, &block)
end

.respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Ensure QC.respond_to?(:enqueue) equals true (ruby 1.9 only)

Returns:

  • (Boolean)


65
66
67
# File 'lib/queue_classic.rb', line 65

def self.respond_to_missing?(method_name, include_private = false)
  default_queue.respond_to?(method_name)
end