Class: Sidejobs::Queue
- Inherits:
-
Object
- Object
- Sidejobs::Queue
- Defined in:
- lib/sidejobs/queue.rb
Instance Method Summary collapse
Instance Method Details
#add(data, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/sidejobs/queue.rb', line 4 def add(data, ={}) Job.create( data: data, queue: ([:queue] || 'default'), priority: ([:priority] || 0), scheduled_at: [:schedule_at] ) end |
#fetch ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/sidejobs/queue.rb', line 13 def fetch Job.where(state: %w(pending failing)).where( 'attempts < ?', Sidejobs.configuration.max_attempts ).where( 'scheduled_at <= ? OR scheduled_at IS NULL', Time.now ).order(priority: :desc).limit(Sidejobs.configuration.batch_size) end |