Module: HireFire::Macro::Deprecated::Delayed::Job
- Included in:
- HireFire::Macro::Delayed::Job
- Defined in:
- lib/hirefire/macro/deprecated/delayed_job.rb
Overview
Provides backward compatibility with the deprecated Delayed::Job macro. For new implementations, refer to HireFire::Macro::Delayed::Job.
Instance Method Summary collapse
-
#queue(*queues) ⇒ Integer
Retrieves the total number of jobs in the specified queue(s).
Instance Method Details
#queue(*queues) ⇒ Integer
Retrieves the total number of jobs in the specified queue(s).
This method supports querying jobs across different ORMs (Object-Relational Mappings) such as ActiveRecord and Mongoid. It allows specifying queue names and priority limits.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/hirefire/macro/deprecated/delayed_job.rb', line 30 def queue(*queues) queues.flatten! = queues.last.is_a?(Hash) ? queues.pop : {} case [:mapper] when :active_record query = ::Delayed::Job.where(failed_at: nil, run_at: ..Time.now.utc) query = query.where(priority: [:min_priority]..) if .key?(:min_priority) query = query.where(priority: ..[:max_priority]) if .key?(:max_priority) query = query.where(queue: queues) unless queues.empty? query.count when :active_record_2 # Note: There is no queue column in delayed_job <= 2.x query = ::Delayed::Job.scoped(conditions: ["run_at <= ? AND failed_at is NULL", Time.now.utc]) query = query.scoped(conditions: ["priority >= ?", [:min_priority]]) if .key?(:min_priority) query = query.scoped(conditions: ["priority <= ?", [:max_priority]]) if .key?(:max_priority) query.count when :mongoid query = ::Delayed::Job.where(:failed_at => nil, :run_at.lte => Time.now.utc) query = query.where(:priority.gte => [:min_priority]) if .key?(:min_priority) query = query.where(:priority.lte => [:max_priority]) if .key?(:max_priority) query = query.where(:queue.in => queues) unless queues.empty? query.count else raise ArgumentError, "Must pass either :mapper => :active_record or :mapper => :mongoid. " \ "For example: HireFire::Macro::Delayed::Job.queue(\"worker\", mapper: :active_record)" end end |