Class: ActiveJob::QueueAdapters::WorkhorseAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/active_job/queue_adapters/workhorse_adapter.rb

Overview

Workhorse adapter for ActiveJob.

Workhorse is a multi-threaded job backend with database queuing for Ruby. Jobs are persisted in the database using ActiveRecord. Read more about Workhorse here.

To use Workhorse, set the queue_adapter config to :workhorse.

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

Examples:

Configuration

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

Instance Method Summary collapse

Instance Method Details

#enqueue(job) ⇒ Workhorse::DbJob

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Enqueues a job for immediate execution.

Parameters:

  • job (ActiveJob::Base)

    The job to enqueue

Returns:



31
32
33
# File 'lib/active_job/queue_adapters/workhorse_adapter.rb', line 31

def enqueue(job)
  Workhorse.enqueue_active_job(job)
end

#enqueue_after_transaction_commit?Boolean

Defines whether enqueuing should happen implicitly to after commit when called from inside a transaction. Most adapters should return true, but some adapters that use the same database as Active Record and are transaction aware can return false to continue enqueuing jobs as part of the transaction.

Returns:

  • (Boolean)

    False because Workhorse is transaction-aware



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

def enqueue_after_transaction_commit?
  false
end

#enqueue_at(job, timestamp = Time.now) ⇒ Workhorse::DbJob

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Enqueues a job for execution at a specific time.

Parameters:

  • job (ActiveJob::Base)

    The job to enqueue

  • timestamp (Time) (defaults to: Time.now)

    When to execute the job

Returns:



41
42
43
# File 'lib/active_job/queue_adapters/workhorse_adapter.rb', line 41

def enqueue_at(job, timestamp = Time.now)
  Workhorse.enqueue_active_job(job, perform_at: timestamp)
end