Class: ActiveJob::QueueAdapters::QueueClassicAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/active_job/queue_adapters/queue_classic_adapter.rb

Overview

queue_classic adapter for Active Job

queue_classic provides a simple interface to a PostgreSQL-backed message queue. queue_classic specializes in concurrent locking and minimizing database load while providing a simple, intuitive developer experience. queue_classic assumes that you are already using PostgreSQL in your production environment and that adding another dependency (e.g. redis, beanstalkd, 0mq) is undesirable.

Read more about queue_classic here.

To use queue_classic set the queue_adapter config to :queue_classic.

Rails.application.config.active_job.queue_adapter = :queue_classic

Defined Under Namespace

Classes: JobWrapper

Instance Method Summary collapse

Constructor Details

#initialize(enqueue_after_transaction_commit: false) ⇒ QueueClassicAdapter

Returns a new instance of QueueClassicAdapter.



22
23
24
# File 'lib/active_job/queue_adapters/queue_classic_adapter.rb', line 22

def initialize(enqueue_after_transaction_commit: false)
  @enqueue_after_transaction_commit = enqueue_after_transaction_commit
end

Instance Method Details

#build_queue(queue_name) ⇒ Object

Builds a QC::Queue object to schedule jobs on.

If you have a custom QC::Queue subclass you’ll need to subclass ActiveJob::QueueAdapters::QueueClassicAdapter and override the build_queue method.



53
54
55
# File 'lib/active_job/queue_adapters/queue_classic_adapter.rb', line 53

def build_queue(queue_name)
  QC::Queue.new(queue_name)
end

#enqueue(job) ⇒ Object

:nodoc:



30
31
32
33
34
# File 'lib/active_job/queue_adapters/queue_classic_adapter.rb', line 30

def enqueue(job) # :nodoc:
  qc_job = build_queue(job.queue_name).enqueue("#{JobWrapper.name}.perform", job.serialize)
  job.provider_job_id = qc_job["id"] if qc_job.is_a?(Hash)
  qc_job
end

#enqueue_after_transaction_commit?Boolean

:nodoc:

Returns:

  • (Boolean)


26
27
28
# File 'lib/active_job/queue_adapters/queue_classic_adapter.rb', line 26

def enqueue_after_transaction_commit? # :nodoc:
  @enqueue_after_transaction_commit
end

#enqueue_at(job, timestamp) ⇒ Object

:nodoc:



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_job/queue_adapters/queue_classic_adapter.rb', line 36

def enqueue_at(job, timestamp) # :nodoc:
  queue = build_queue(job.queue_name)
  unless queue.respond_to?(:enqueue_at)
    raise NotImplementedError, "To be able to schedule jobs with queue_classic " \
      "the QC::Queue needs to respond to `enqueue_at(timestamp, method, *args)`. " \
      "You can implement this yourself or you can use the queue_classic-later gem."
  end
  qc_job = queue.enqueue_at(timestamp, "#{JobWrapper.name}.perform", job.serialize)
  job.provider_job_id = qc_job["id"] if qc_job.is_a?(Hash)
  qc_job
end