module Fleiss::Backend::ActiveRecord::Concern::ClassMethods

Public Instance Methods

enqueue(job, scheduled_at: nil) click to toggle source

@param [ActiveJob::Base] job the job instance @option [Time] :scheduled_at schedule job at

# File lib/fleiss/backend/active_record/concern.rb, line 44
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) click to toggle source

@return [ActiveRecord::Relation] in-progress scope

# File lib/fleiss/backend/active_record/concern.rb, line 38
def in_progress(owner)
  started.not_finished.where(owner: owner)
end
pending(now = Time.zone.now) click to toggle source

@return [ActiveRecord::Relation] pending scope

# File lib/fleiss/backend/active_record/concern.rb, line 28
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) click to toggle source
# File lib/fleiss/backend/active_record/concern.rb, line 20
def wrap_perform(&block)
  connection_pool.with_connection(&block)
rescue ::ActiveRecord::StatementInvalid
  ::ActiveRecord::Base.clear_active_connections!
  raise
end