Module: Arj::Query

Included in:
Arj, Test, Test::Job
Defined in:
lib/arj/query.rb

Overview

ActiveRecord-style query methods (where, first, last, etc.), but for jobs.

Example usage:

class SampleJob < ActiveJob::Base
  include Arj::Query
end

SampleJob.set(queue_name: 'some queue').perform_later('some arg')
job = job.where(queue_name: 'some queue').first
job.perform_now

This module is also included in the Arj module.

Example usage:

class SampleJob < ActiveJob::Base; end

SampleJob.set(queue_name: 'some queue').perform_later('some arg')
job = Arj.where(queue_name: 'some queue').first
job.perform_now

Note that all query methods delegate to ClassMethods#all. Override ClassMethods#all to customize. For instance, to create a job group:

class FooBarJob < ActiveJob::Base; end
class FooBazJob < ActiveJob::Base; end

module FooJobs
  include Arj::Query

  def self.all
    Arj.where(job_class: [FooBarJob, FooBazJob].map(&:name))
  end
end

FooBarJob.perform_later
FooBazJob.perform_later
FooJobs.available.first # Returns the first available job of type FooBarJob or FooBazJob.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(clazz) ⇒ Class

Adds ClassMethods when this module is included.

Returns:

  • (Class)


82
83
84
# File 'lib/arj/query.rb', line 82

def self.included(clazz)
  clazz.extend ClassMethods
end