Module: Fleiss::Backend::ActiveRecord::Concern::ClassMethods
- Defined in:
- lib/fleiss/backend/active_record/concern.rb
Instance Method Summary collapse
- #enqueue(job, scheduled_at: nil) ⇒ Object
-
#in_progress(owner) ⇒ ActiveRecord::Relation
In-progress scope.
-
#pending(now = Time.zone.now) ⇒ ActiveRecord::Relation
Pending scope.
Instance Method Details
#enqueue(job, scheduled_at: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fleiss/backend/active_record/concern.rb', line 35 def enqueue(job, scheduled_at: nil) scheduled_at = scheduled_at ? Time.zone.at(scheduled_at) : Time.zone.now expires_at = scheduled_at + job.ttl.seconds if job.respond_to?(:ttl) create!( payload: JSON.dump(job.serialize), queue_name: job.queue_name, priority: job.priority.to_i, scheduled_at: scheduled_at, expires_at: expires_at, ).id end |
#in_progress(owner) ⇒ ActiveRecord::Relation
Returns in-progress scope.
29 30 31 |
# File 'lib/fleiss/backend/active_record/concern.rb', line 29 def in_progress(owner) started.not_finished.where(owner: owner) end |
#pending(now = Time.zone.now) ⇒ ActiveRecord::Relation
Returns pending scope.
19 20 21 22 23 24 25 26 |
# File 'lib/fleiss/backend/active_record/concern.rb', line 19 def pending(now=Time.zone.now) not_finished .not_expired(now) .not_started .where(arel_table[:scheduled_at].lteq(now)) .order(priority: :desc) .order(scheduled_at: :asc) end |