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.
- #wrap_perform(&block) ⇒ Object
Instance Method Details
#enqueue(job, scheduled_at: nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fleiss/backend/active_record/concern.rb', line 39 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.
33 34 35 |
# File 'lib/fleiss/backend/active_record/concern.rb', line 33 def in_progress(owner) started.not_finished.where(owner: owner) end |
#pending(now = Time.zone.now) ⇒ ActiveRecord::Relation
Returns pending scope.
23 24 25 26 27 28 29 30 |
# File 'lib/fleiss/backend/active_record/concern.rb', line 23 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 |
#wrap_perform(&block) ⇒ Object
18 19 20 |
# File 'lib/fleiss/backend/active_record/concern.rb', line 18 def wrap_perform(&block) connection_pool.with_connection(&block) end |