Module: Marj
- Extended by:
- JobsInterface
- Defined in:
- lib/marj.rb,
lib/marj/record.rb,
lib/marj/relation.rb,
lib/marj/jobs_interface.rb
Overview
A minimal database-backed ActiveJob queueing backend.
The Marj module provides methods for interacting with enqueued jobs. These methods accept, return and yield ActiveJob
objects rather than ActiveRecord
objects. Returned jobs are ordered by due date. To query the database directly, use Record.
Example usage:
Marj.all # Returns all enqueued jobs.
Marj.queue # Returns jobs in the specified queue(s).
Marj.due # Returns jobs which are due to be executed.
Marj.next # Returns the next job(s) to be executed.
Marj.count # Returns the number of enqueued jobs.
Marj.where # Returns jobs matching the specified criteria.
Marj.perform_all # Executes all jobs.
Marj.discard_all # Discards all jobs.
Marj.discard # Discards the specified job.
Query methods can also be chained:
Marj.due.where(job_class: SomeJob).next # Returns the next SomeJob that is due
Note that by default, Marj uses Record to interact with the jobs
table. To use a different record class, set Marj.record_class. To simply override the table name, set Marj.table_name before loading ActiveRecord
.
Defined Under Namespace
Modules: JobsInterface Classes: Record, Relation
Constant Summary collapse
- VERSION =
The Marj version.
'4.1.0'
Class Attribute Summary collapse
-
.record_class ⇒ Class, String
The name of the
ActiveRecord
class. -
.table_name ⇒ Symbol, String
The name of the database table.
Class Method Summary collapse
-
.all ⇒ Marj::Relation
Returns a Relation for all jobs in the order they should be executed.
-
.discard(job) ⇒ Integer
Discards the specified job.
Methods included from JobsInterface
count, discard_all, due, next, perform_all, queue, where
Class Attribute Details
.record_class ⇒ Class, String
The name of the ActiveRecord
class. Defaults to Marj::Record
.
47 |
# File 'lib/marj.rb', line 47 attr_writer :record_class |
.table_name ⇒ Symbol, String
The name of the database table. Defaults to :jobs
.
56 57 58 |
# File 'lib/marj.rb', line 56 def table_name @table_name end |
Class Method Details
.all ⇒ Marj::Relation
Returns a Relation for all jobs in the order they should be executed.
61 62 63 |
# File 'lib/marj.rb', line 61 def all Marj::Relation.new(Marj.record_class.ordered) end |
.discard(job) ⇒ Integer
Discards the specified job.
68 69 70 |
# File 'lib/marj.rb', line 68 def discard(job) all.where(job_id: job.job_id).discard_all end |