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



67
68
69
70
71
# File 'lib/queue_classic.rb', line 67

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

.log(data) ⇒ Object



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

def self.log(data)
  Scrolls.log({:lib => :queue_classic}.merge(data))
end

.log_yield(data) ⇒ Object



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

def self.log_yield(data)
  begin
    t0 = Time.now
    yield
  rescue => e
    log({:level => :error, :error => e.class, :message => e.message.strip}.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()



63
64
65
# File 'lib/queue_classic.rb', line 63

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