Module: Marj

Defined in:
lib/marj.rb,
lib/marj/record.rb

Overview

A minimal database-backed ActiveJob queueing backend.

The Marj module provides the following methods:

  • query - Queries enqueued jobs

  • discard - Discards a job, by default by executing after_discard callbacks and delegating to delete

  • delete - Deletes a job

It is possible to call the above methods on the Marj module itself or on any class which includes it.

Example usage:

Marj.query(:first) # Returns the first job
Marj.discard(job)  # Discards the specified job
Marj.delete(job)  # Deletes the specified job

class ApplicationJob < ActiveJob::Base
  include Marj
end

class SomeJob < ApplicationJob;
  def perform; end
end

job = ApplicationJob.query(:first) # Returns the first enqueued job
job = SomeJob.query(:first)        # Returns the first enqueued job with job_class SomeJob
ApplicationJob.discard(job)        # Discards the specified job
ApplicationJob.delete(job)         # Deletes the specified job
job.discard                        # Discards the job
job.delete                         # Deletes the job

See github.com/nicholasdower/marj

Defined Under Namespace

Modules: ClassMethods Classes: Record

Constant Summary collapse

VERSION =

The Marj version.

'6.0.0'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.delete(job) ⇒ ActiveJob::Base

Deletes the record associated with the specified job.

Returns:

  • (ActiveJob::Base)

    the deleted job



92
93
94
# File 'lib/marj.rb', line 92

def self.delete(job)
  queue_adapter.delete(job)
end

.discard(job) ⇒ ActiveJob::Base

Discards the specified job.

Returns:

  • (ActiveJob::Base)

    the discarded job



87
88
89
# File 'lib/marj.rb', line 87

def self.discard(job)
  queue_adapter.discard(job)
end

.query(*args, **kwargs) ⇒ Object

Queries enqueued jobs. Similar to ActiveRecord.where with a few additional features:

  • Symbol arguments are treated as ActiveRecord scopes.

  • If only a job ID is specified, the corresponding job is returned.

  • If :limit is specified, the maximum number of jobs is limited.

  • If :order is specified, the jobs are ordered by the given attribute.

By default jobs are ordered by when they should be executed.

Example usage:

query                       # Returns all jobs
query(:all)                 # Returns all jobs
query(:due)                 # Returns jobs which are due to be executed
query(:due, limit: 10)      # Returns at most 10 jobs which are due to be executed
query(job_class: Foo)       # Returns all jobs with job_class Foo
query(:due, job_class: Foo) # Returns jobs which are due to be executed with job_class Foo
query(queue_name: 'foo')    # Returns all jobs in the 'foo' queue
query(job_id: '123')        # Returns the job with job_id '123' or nil if no such job exists
query('123')                # Returns the job with job_id '123' or nil if no such job exists


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

def self.query(*args, **kwargs)
  queue_adapter.query(*args, **kwargs)
end

Instance Method Details

#deleteActiveJob::Base

Deletes the record associated with this job.

Returns:

  • (ActiveJob::Base)

    this job



106
107
108
# File 'lib/marj.rb', line 106

def delete
  self.class.queue_adapter.delete(self)
end

#discardActiveJob::Base

Deletes this job.

Returns:

  • (ActiveJob::Base)

    this job



99
100
101
# File 'lib/marj.rb', line 99

def discard
  self.class.queue_adapter.discard(self)
end