Class: Marj::Record
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Marj::Record
- Defined in:
- lib/marj/record.rb
Overview
The default ActiveRecord
class.
Class Method Summary collapse
-
.due ⇒ ActiveRecord::Relation
Returns an
ActiveRecord::Relation
scope for enqueued jobs with ascheduled_at
that is eithernull
or in the past. -
.ordered ⇒ ActiveRecord::Relation
Returns an
ActiveRecord::Relation
scope for jobs ordered bypriority
(null
last), thenscheduled_at
(null
last), thenenqueued_at
.
Instance Method Summary collapse
-
#as_job ⇒ ActiveJob::Base
Returns a job object for this record which will update the database when successfully executed, enqueued or discarded.
Class Method Details
.due ⇒ ActiveRecord::Relation
Returns an ActiveRecord::Relation
scope for enqueued jobs with a scheduled_at
that is either null
or in the past.
62 63 64 |
# File 'lib/marj/record.rb', line 62 def due where('scheduled_at IS NULL OR scheduled_at <= ?', Time.now.utc) end |
.ordered ⇒ ActiveRecord::Relation
Returns an ActiveRecord::Relation
scope for jobs ordered by priority
(null
last), then scheduled_at
(null
last), then enqueued_at
.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/marj/record.rb', line 70 def ordered order( Arel.sql(<<~SQL.squish, Time.now.utc) CASE WHEN scheduled_at IS NULL OR scheduled_at <= ? THEN 0 ELSE 1 END, CASE WHEN priority IS NULL THEN 1 ELSE 0 END, priority, CASE WHEN scheduled_at IS NULL THEN 1 ELSE 0 END, scheduled_at, enqueued_at SQL ) end |
Instance Method Details
#as_job ⇒ ActiveJob::Base
Returns a job object for this record which will update the database when successfully executed, enqueued or discarded.
53 54 55 |
# File 'lib/marj/record.rb', line 53 def as_job Marj.send(:to_job, self) end |